CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   Why is c++ taking longer than MATLAB? (https://www.cfd-online.com/Forums/main/186902-why-c-taking-longer-than-matlab.html)

rleader April 25, 2017 03:36

Why is c++ taking longer than MATLAB?
 
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?

akidess April 25, 2017 04:00

You wrote poorly optimized code.

Abderahmane April 25, 2017 14:14

parrallel solution
 
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 :)

flotus1 April 25, 2017 14:23

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.

LuckyTran April 25, 2017 20:47

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?

abkahraman April 30, 2017 12:05

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?

Wingman April 30, 2017 13:34

I don't know how your code is or what it does. Are they using sparse matrices in Matlab? They reduce the calculation allot.


All times are GMT -4. The time now is 04:50.