CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   C++ Vs Fortran (https://www.cfd-online.com/Forums/main/16404-c-vs-fortran.html)

Dave February 26, 2009 07:19

C++ Vs Fortran
 
Hi Guys, I'm about to start writing a pretty big CFD code to solve transonic flow about a moving airfoil. I have lots of experience in Fortran 90 and have dabbled a little in C++.

Which language would you suggest I use for a computationally expensive process? I have been told that Fortran usually leads to faster executables (i.e. less computation time for a given system) but some colleagues dislike Fortran and opt for C++.

I have no feelings either way - I would like to choose whichever program will give the fastest executable.

Could someone please offer some advice?

mecpp February 26, 2009 07:51

Re: C++ Vs Fortran
 
my PERSONAL choice is c++. If you ask me why, my answer would be felxibility.


pc February 26, 2009 08:44

Re: C++ Vs Fortran
 
Fortran = FORmula TRANslation

It was designed for, and continues to be optimized for, computationally intensive algorithms.

ag February 26, 2009 08:45

Re: C++ Vs Fortran
 
Go with what you know - use the FORTRAN.

Steve February 26, 2009 09:02

Re: C++ Vs Fortran
 
This is an entirely religious debate, fought over many years with no hint of logic or evidence.

For ultimate speed, forget high level languages and use assembly.

pc February 26, 2009 10:23

Re: C++ Vs Fortran
 
Steve has put it rather well. Which is the "best" programming language for CFD has been argued ad nauseum on this forum. You can search the forum for many past discussions on this matter.

You'll be spending a lot of time coding and debugging - use the language in which you are most proficient.

Balduin Bankerotti February 26, 2009 10:26

Re: C++ Vs Fortran
 
... or look if it is possible to use an existing library like OpenFOAM to solve your problem much faster.


Bill February 26, 2009 13:39

Re: C++ Vs Fortran
 
as others, use what is comfortable for you, for a good programmer, OOP etc (which are sound after cpp) are more concept, such that for an expert it's possible to implement it within fortran as well,


Hadian February 28, 2009 01:22

Re: C++ Vs Fortran
 
If the execution time is the only matter you concern, there is no difference between Fortran,C and C++. the difference of cpu time in different compilers of fortran (or c or c++) is much more that difference between c++ and fortran compiler of the same company. you can find many benchmarks on the internet. Hadian

Tom February 28, 2009 05:17

Re: C++ Vs Fortran
 
This depends on what features you use. A straight fortran code compared to a C++ code exploiting OOP (i.e. when the code is really C++ and not C) then the speed difference can be considerable (fortran can be > 2 times faster).

You can do the same thing to fortran (using the same compiler); e.g. compare two codes that do exactly the samething but write one in straight fortran and the other using derived types and operator overloading. Another way of putting this is that the choice of programming method is more significant than the choice of compiler; eg. g77 can actually be faster than intel ifort if you exploit derived types and operator overloading in ifort (however on the same fortran code ifort will be faster).

kenn k.q. zhang March 1, 2009 15:02

Re: C++ Vs Fortran
 
Fortran is faster than c++???

hoho,

how do you know???

from words of mouth???

how did they know???

did they show you solid comparison of speed??

or they also learned this from word of mouth???

come on,

how can c++, invented 1970 by the brilliant computerist, be a lot slower than fortran, which was invented in 1950s

and, just use your common sense --since you have lots of programming experience, how can a computer code which largely formed by loops be slower than the same code which have the same loops but differ in a couple of time-negligible operations???

100 times more importantly,

fortran promotes ugly programming style;

in contrast, c++ promotes beautiful programming;

anyone, if she/he tells me she/he is using fortran and knows little c++, my first response is this is a poor person in scientific computing or this person was ill-educated or ill-informed by some old researchers who know nothing about CFD and programming.


kenn k.q. zhang March 1, 2009 15:02

Re: C++ Vs Fortran
 
Fortran is faster than c++???

hoho,

how do you know???

from words of mouth???

how did they know???

did they show you solid comparison of speed??

or they also learned this from word of mouth???

come on,

how can c++, invented 1970 by the brilliant computerist, be a lot slower than fortran, which was invented in 1950s

and, just use your common sense --since you have lots of programming experience, how can a computer code which largely formed by loops be slower than the same code which have the same loops but differ in a couple of time-negligible operations???

100 times more importantly,

fortran promotes ugly programming style;

in contrast, c++ promotes beautiful programming;

anyone, if she/he tells me she/he is using fortran and knows little c++, my first response is this is a poor person in scientific computing or this person was ill-educated or ill-informed by some old researchers who know nothing about CFD and programming.

--------------------------------------------------------------------------------


Andrew March 1, 2009 17:45

Re: C++ Vs Fortran
 
What utter nonsense.

Bill March 2, 2009 01:55

Re: C++ Vs Fortran
 
kenn k.q. zhang:

sorry but i mean your reply speech without idea!

for one that know programming language is almost no matter

In generl Fortran is always faster than C/C++ (because several think like array bound check, .. in c++), *but* it is possible to improve C/C++ speed by changing some compiler swtich, *but* steel Fortran will be a bit faster

Well, if you do not think so, just provide a sample to prove your claim (a short Fortran & C++ programm plus required command for compile, ...), then we can accept that you have idea about what you said!!! (else i mean verbosity)

Tom March 2, 2009 05:14

Re: C++ Vs Fortran
 
Well considering he can't get his facts right (C++ in 1970? 1979 would be more accurate) I think it's best to ignore him.

jughead March 2, 2009 10:16

Re: C++ Vs Fortran
 
He is right about Fortran promoting ugly programming.

C++ is more modular and scalable. Fortran tends to be a mess. It is not OO and therefore has several limitations.

However, I think we have yet to see a state-of-the-art CFD C++ code implementation because there is a lack of people who are experts in both.


Tom March 2, 2009 10:40

Re: C++ Vs Fortran
 
You've obviously never done any supercomputer optimization or you wouldn't think that - OOP is a big no-no on these types of machines since it is very difficult for the compiler to optimize such code (read my first post and try a few examples yourself). Even in computer science there's been a bit of a backlash against OOP (as implemented in C++ particularly) for the last few years.

Anyway, cleanly written FORTRAN 90/95 is relatively easy to read and is well suited to programming numerical analysis problems.

Bill March 2, 2009 11:18

Re: C++ Vs Fortran
 
jughead and others:

lets to repeat what i have implied in the previous posts, OOP is a *concept* not a programming language, this concept can be implemented into any moderin language like Fortran, C, CPP

however, CPP provide some instructions that make it more easy (and more readable) but maybe in expense of cost

you can read about OOP in C to get what i imply (e.g. GLIB is somewho OOP in C, note: C is not known as OOP language for some peoples)

by above argument: it's obvious that programming syle is different from language and you can write an slow programm to both of Fortran & CPP

successful programmer is who that know how data and instruction is manipolated by CPU, e.g. cache coherency, parallel operation etc.

considering all things, a plane Fortran code usually perform a bit faster than a palne CPP code under the same condition

a March 2, 2009 11:33

Re: C++ Vs Fortran
 
I tend to use both. C++ at the design step and Fortran at the production step.

- I disagree on the fact that Fortran provides an ugly code with poor modularity (have a look on the Fortran 2003 features that are marvelous and appear now progressively in compilers). However it tends to make you lazy (at least me). This is why doing serious C++ as a first draft pushes me a little bit in terms of imagination. The double work overhead is not so much given the final quality that increases the long term productivity.

- I also disagree on the fact that C++ codes are slower. This is no more true. However, doing C++ is slower on the programming side: learning curve, potentiality of the language turned towards software engineering that is for me another field than strict scientific programming (unless your code is not your tool but the final product you wish to sell as a software) such that you expose yourself to traps uselessly.

- Thirdly and lastly, it is known that the C++ commitee is (apparently) not receptive to the requests made specifically for/by people wanting to use it for scientific computing. It invokes the same reason as me: C++ is for software engineering and must keep its goals clear. It says that something has been designed and is continually updated by paying attention to scientific programmer needs and that this thing is... Fortran (I remember having read something on informit.com). In other words, Fortran works specifically for us.

Steve March 2, 2009 12:51

Re: C++ Vs Fortran
 
Another consideration is the operating system where you will be running. Programming for Linux (and other *nix) is naturally easiest in C, because you have access to all the same functions that the OS does.

But anyway, not many people ever use rational decision making when choosing a language. It's normally a hunt for supporting evidence for an a priori decision.


All times are GMT -4. The time now is 22:58.