CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Why is c++ taking longer than MATLAB?

Register Blogs Community New Posts Updated Threads Search

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 25, 2017, 04:36
Unhappy Why is c++ taking longer than MATLAB?
  #1
New Member
 
Rob
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, 05:00
Default
  #2
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 30
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, 15:14
Default parrallel solution
  #3
New Member
 
A.MAROUF
Join Date: Dec 2016
Posts: 22
Rep Power: 9
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, 15:23
Default
  #4
Super Moderator
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,427
Rep Power: 49
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, 21:47
Default
  #5
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,751
Rep Power: 66
LuckyTran has a spectacular aura aboutLuckyTran 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, 13:05
Default
  #6
New Member
 
Ali Berk Kahraman
Join Date: Dec 2015
Location: Braunschweig, Germany
Posts: 14
Rep Power: 10
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, 14:34
Default
  #7
Member
 
William
Join Date: Aug 2016
Posts: 56
Rep Power: 10
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

Reply

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


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
How to start Fluent with Matlab?? Jay Hu FLUENT 8 November 9, 2022 07:30
Export/Import data contour plots with Matlab meangreen FLUENT 11 October 28, 2020 11:06
Very small Matlab job: post-processing OpenFOAM (.CSV) results RbBb CFD Freelancers 1 July 11, 2016 10:00
Linking with Matlab?? LostinSpace Phoenics 0 March 25, 2013 06:39
Live connection Matlab VS OF levka OpenFOAM Running, Solving & CFD 0 July 10, 2012 05:15


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