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

Comparison between C/C++ and Fortran?

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 5, 2011, 17:54
Default
  #41
Senior Member
 
cfdnewbie
Join Date: Mar 2010
Posts: 557
Rep Power: 20
cfdnewbie is on a distinguished road
Quote:
Originally Posted by DoHander View Post
For parallel CPU processing I think C++ is as fast as Fortran today.
I beg to differ here, Do....a large part of numerics ends up being matrix vector multiplications, and we did some testing with that a while ago (C vs Fortran, not C++, but as far as I know the basic matmul routines in C and C++ are identical, right?).
We found that Fortran is indeed more optimized in that discipline, i.e. faster. I'm no expert on this, but one who is told me that comes from the way Fortran arranges matrices in memory (array style), while C does it in a single 1D vector.

Quote:
Today it is not a question about language, but about what compiler and libraries you can use to do your computation.

Do
That's true, plus which hardware you have available. Modern compilers can do a lot of great (and stupid) optimizations!
cfdnewbie is offline   Reply With Quote

Old   September 5, 2011, 20:57
Default
  #42
Senior Member
 
Martin Hegedus
Join Date: Feb 2011
Posts: 500
Rep Power: 19
Martin Hegedus is on a distinguished road
I think optimization should be defined.

Personally, my bottleneck is not CPU, but the memory bus. Whether it is C, C++, or FORTRAN is mostly unimportant (assuming the programmer is creating somewhat efficient code) for parallel operation. What is important is developing an algorithm which feeds the CPU as fast as possible. What this means is that the programmer must minimize the k loops (i being the fastest loop)

Of course, one can slow down C++ by excessive calls to the virtual table, but I assume that is being kept at the top level and inline functions are used where appropriate, etc.
Martin Hegedus is offline   Reply With Quote

Old   September 5, 2011, 21:00
Default
  #43
Senior Member
 
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,273
Rep Power: 34
arjun will become famous soon enougharjun will become famous soon enough
This is how I think on fortran vs C++.

If you do exact same thing from both languages then Fortran indeed be little bit or significantly faster than C++. Run simple tests like Matrix vector multiplications etc and you will notice that Fortran is faster than C++. Most of the tests just do this and thus fortran seems to language of choice.

But this is not so simple. Tests are good and have their place but in real life you will NOT be running these tests to get your results. For example take CFD, a navier stokes solver is much more than just a matrix vector multiplier. It is a complicated algorithm when implemented.

Now the efficiency of simulation all depends on how this algorithm is implemented. If I can implement it using c or c++ such that it is faster than Fortran than it does not matter whether in tests fortran was faster. This is not going to help if all you are going to do is write poorer algorithm compared to what a guy with C++ wrote.

You might save say 5 to 10% of time with faster language but if slower language allowed you better algorithm you might be faster by many times.

So chose the algorithm and then chose language that suits it.
arjun is online now   Reply With Quote

Old   September 5, 2011, 21:01
Default
  #44
Senior Member
 
Martin Hegedus
Join Date: Feb 2011
Posts: 500
Rep Power: 19
Martin Hegedus is on a distinguished road
BTW, sometimes an algorithm is faster if a value (for example speed of sound) is repeatedly calculated when required, rather than saved in memory and then retrieved when needed.
Martin Hegedus is offline   Reply With Quote

Old   September 5, 2011, 22:41
Default
  #45
Senior Member
 
lakeat's Avatar
 
Daniel WEI (老魏)
Join Date: Mar 2009
Location: Beijing, China
Posts: 689
Blog Entries: 9
Rep Power: 21
lakeat is on a distinguished road
Send a message via Skype™ to lakeat
Well this is the MAIN Forum!
Okay, you guys are not just staying on the OF forums. I wonder how many hours you are walking around on the cfdonline everyday.
__________________
~
Daniel WEI
-------------
Boeing Research & Technology - China
Beijing, China
Email
lakeat is offline   Reply With Quote

Old   September 6, 2011, 00:52
Default
  #46
Senior Member
 
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,273
Rep Power: 34
arjun will become famous soon enougharjun will become famous soon enough
Quote:
Originally Posted by lakeat View Post
Well this is the MAIN Forum!
Okay, you guys are not just staying on the OF forums. I wonder how many hours you are walking around on the cfdonline everyday.

4 years ago i used on on cfd-online almost all the time. Now a days sometimes i do not visit for days.

I spend most of my time on photography forums. It is lot of fun trying to pick faults with cameras that we will never buy. They are more active and lot of arguing going on. CFD-online is no where near to them on fun factor.
arjun is online now   Reply With Quote

Reply


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
Fortran Compiler-CFX12.1 Araz CFX 13 March 27, 2017 05:37
Array Comparison in Fortran 90/95 M Malik Main CFD Forum 4 September 11, 2008 14:14
visual fortran Monica Main CFD Forum 1 August 28, 2004 20:45
Fortran77 or Fortran 90 Swapnil CFX 2 November 26, 2002 15:16
Why Favoring Fortran over C/C++? Zi-Wei Chiou Main CFD Forum 35 September 26, 2001 09:34


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