CFD Online Logo CFD Online URL
Home > Forums > General Forums > Main CFD Forum

Why is c++ taking longer than MATLAB?

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree3Likes
  • 1 Post By rleader
  • 1 Post By Abderahmane
  • 1 Post By LuckyTran

LinkBack Thread Tools Search this Thread Display Modes
Old   April 25, 2017, 03:36
Unhappy Why is c++ taking longer than MATLAB?
New Member
Join Date: Apr 2017
Posts: 1
Rep Power: 0
rleader is on a distinguished road
Comparing my run times with other people coding the same method is revealing that my c++ code is taking about 30% longer than their MATLAB codes when it should be much, much faster. I cannot seem to figure out why is this.

I use Visual studio 2015 community as my compiler.

I use of Ox (full optimization).

My hardware is comparable to my peers.

Anyone have any ideas?
Ankit Sharma likes this.
rleader is offline   Reply With Quote

Old   April 25, 2017, 04:00
Senior Member
akidess's Avatar
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,379
Rep Power: 26
akidess will become famous soon enough
You wrote poorly optimized code.
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
akidess is offline   Reply With Quote

Old   April 25, 2017, 14:14
Default parrallel solution
New Member
Join Date: Dec 2016
Posts: 22
Rep Power: 6
Abderahmane is on a distinguished road
Well from what i know, is that i compared once codes : Python & Matlab & Fortran , the Fortran is the most faster.

To answer your question :

you can install ( openmpi ) than try some tutorials to make your code parallel and if your machine has 4 processors your code will be 4Xtimes faster
Ankit Sharma likes this.
Abderahmane is offline   Reply With Quote

Old   April 25, 2017, 14:23
Senior Member
flotus1's Avatar
Join Date: Jun 2012
Location: Germany
Posts: 2,730
Rep Power: 38
flotus1 has a spectacular aura aboutflotus1 has a spectacular aura about
If he managed to get slower execution in c++ than in matlab I don't think parallelization is the next logical step.
He should really investigate what slows down his code, for example by using a profiling tool.
flotus1 is offline   Reply With Quote

Old   April 25, 2017, 20:47
Senior Member
Lucky Tran
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 4,119
Rep Power: 50
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
For many built-in functions, Matlab accelerates the routine by running them in parallel. I.e. max, min, etc. Is your c++ purely serial? Are you even comparing the same code?
KaLium likes this.
LuckyTran is offline   Reply With Quote

Old   April 30, 2017, 12:05
New Member
Ali Berk Kahraman
Join Date: Dec 2015
Location: Istanbul, Turkey
Posts: 11
Rep Power: 7
abkahraman is on a distinguished road
Since you are using Visual Studio, if you forgive me for being so obvious, are you sure you are "running" the code? Perhaps you are debugging the code using built in F5 (at least this was the way it was in an older Visual Express) so the IDE is actually losing time debugging your time. You might want to try reaching the directory where your .exe file is and run it from there perhaps?
abkahraman is offline   Reply With Quote

Old   April 30, 2017, 13:34
Join Date: Aug 2016
Posts: 56
Rep Power: 6
Wingman is on a distinguished road
I don't know how your code is or what it does. Are they using sparse matrices in Matlab? They reduce the calculation allot.
Wingman is offline   Reply With Quote


c++, compiler, matlab, speed, visual studio

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Export/Import data contour plots with Matlab meangreen FLUENT 11 October 28, 2020 10:06
How to start Fluent with Matlab?? Jay Hu FLUENT 6 November 10, 2018 03:20
Very small Matlab job: post-processing OpenFOAM (.CSV) results RbBb CFD Freelancers 1 July 11, 2016 09:00
Linking with Matlab?? LostinSpace Phoenics 0 March 25, 2013 05:39
Live connection Matlab VS OF levka OpenFOAM Running, Solving & CFD 0 July 10, 2012 04:15

All times are GMT -4. The time now is 05:57.