CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   Comparison between C/C++ and Fortran? (https://www.cfd-online.com/Forums/main/759-comparison-between-c-c-fortran.html)

cfdnewbie September 5, 2011 17:54

Quote:

Originally Posted by DoHander (Post 322996)
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!

Martin Hegedus September 5, 2011 20:57

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.

arjun September 5, 2011 21:00

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.

Martin Hegedus September 5, 2011 21:01

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.

lakeat September 5, 2011 22:41

Well this is the MAIN Forum! :D
Okay, you guys are not just staying on the OF forums. I wonder how many hours you are walking around on the cfdonline everyday.:)

arjun September 6, 2011 00:52

Quote:

Originally Posted by lakeat (Post 323027)
Well this is the MAIN Forum! :D
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. :D


All times are GMT -4. The time now is 09:39.