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)

kenn k.q. zhang March 6, 2009 15:53

Re: C++ Vs Fortran
 
c++ is analogous to "english"

fortran is analogous to the local dielect languange in my hometown in china

so,

which one to choose for scientific computing???

ag March 6, 2009 19:57

Re: C++ Vs Fortran
 
These last two comments are absolutely asinine. Who cares if IEEE "discriminates" against us "poor CFD people"? I've got a job to do (as I assume the original poster does) and my self-esteem doesn't hang on what others say about FORTRAN. I use it because I know it better, so I can get my job done faster - which is the most important metric for the original poster.

ztdep March 7, 2009 07:23

Re: C++ Vs Fortran
 
since you have a large project to do, and you have many years experience , fortran is the first choise.

since your code is for the computation, both language will do the same thing.

you can find a lot of code written in fortran to do the cfd

RenardP March 21, 2009 09:57

Both Fortran and C++ are suitable for developing a large CFD code.
Besides today you can call Fotran from a C++ function or vice versa in a straightforward manner.
In the end all it matters is how familiar are you with one of this languages.

saha March 24, 2009 18:02

i dont have so experience in CFD ! but my well educated proff perefer Fortran!

sbaffini March 24, 2009 21:18

I think that some statements about the Fortan are really unfair.

Actually, all the old bad things about the Fortran (which also promoted the bad, and very illogical indeed, programming style) have been, more or less, removed while keeping the language almost the same.

It's probably not suited for graphics (not at all) but, all you need in CFD is an input file and, even for the more advanced codes on the programming side (unstructured mesh commercial solvers), it is a simple text file and there is no way in which any different compiled language can be better than the Fortran in simply treating the numerical data as it happens in CFD codes.

RenardP March 24, 2009 21:55

Fortran is fine for basic CFD, I did my fair share of coding in Fortran 77 and Fortran 90.

But when you need more complicated data structures like a linked list or advanced string operation facility, C++ with STL is far more easy to use. In Fortran you will need to build from scratch a lot data structures.

I'm sure you can develop a CFD code using only good old arrays but when you need to interpret/read an unstructured mesh you will really appreciate a linked list.

I know you can implement any "modern" data structures in Fortran 90 - 95 - 2003 but I bet nobody is happy when he must implement this.

The other face of the coin is that in Fortran you already have implemented a lot of good mathematical routines and in C/C++ aparently not. Well nowdays you have a lot Open Source mathematical subroutines in C/C++ like GSL, FFTW ....

From a modern perspective I will always recomand to simply use C++ for new codes and if you already have good, tested, old Fortran routines simply link these with your C++ code.

jugghead March 25, 2009 05:58

I would like to see object-oriented CFD codes and application of rigorous unit testing and version control.

jwm March 27, 2009 14:09

Matlab
 
Folks,

I know that interpreted MATLAB is about a thousand times slower than a compiled C or FORTRAN program.

How does a compiled MATLAB program stack up, speedwise?

Marcus April 1, 2009 09:26

Quote:

Originally Posted by RenardP (Post 210223)
Both Fortran and C++ are suitable for developing a large CFD code.
Besides today you can call Fotran from a C++ function or vice versa in a straightforward manner.
In the end all it matters is how familiar are you with one of this languages.

I wish it were that simple. I consistently run into the "legacy code" argument, saying I shouldn't bother to write any CFD apps in anything but Fortran because all the old dinosaur titans of industry are stuck with it. As for cross-compiling, something just seems wrong about calling C/C++ from an existing Fortran numerical code, instead of vice versa :)

Quote:

Originally Posted by jwm (Post 211077)
Folks,

I know that interpreted MATLAB is about a thousand times slower than a compiled C or FORTRAN program.

How does a compiled MATLAB program stack up, speedwise?

I personally can't give you any hard numbers, but there is a Matlab webinar this Friday, April 3 on "strategies and techniques for speeding up your MATLAB applications." Info available here if you're interested: https://mathworksevents.webex.com/ma...=a&d=667286592

RenardP April 1, 2009 15:26

I've used gfortran (for compiling Fortran code),gcc (for C code and g++(for C++) and I've called Fortran from C/C++ and vice-versa without a problem.

You have to be sure that you use compatible compilers (GNU in my case or you can always use the Intel Fortran and C++ compilers for the same job).

I never said these is simple, you have to do a lot of checking because Fortran and C "thinks" differently (e.g. array storing order) but in the end it will work if you are determined to do that.

If you develop a new code from scratch and you know both C/C++ and Fortran I will advise you to use C++.

Matlab - is simply not well suited for serious CFD (it will work well for simple proof of concept 1D applications). If you will have a large code think only at the bunch of m code you will have for each function. Other thing - how much memory uses your Matlab only for running his interpretor (start Matlab and check how much RAM he uses) ? How long will take you to load into Matlab a 50MB file with numbers ? :).

Paul

RenardP April 1, 2009 15:28

And in the end a small question - how much are you willing to pay for a Matlab parallel edition (I suppose you will have to buy a license for each computer node you intend to use)?

bohluly April 4, 2009 05:26

We checked it befor ! speed of Fortran and C++
 
There are several major problems with using C, for numerical programming. Mainly, the languages were designed for systems programming, not high precision, efficient number crunching and mathematical calculations.
in our search, we have not found any reason why FORTRAN should not be used for numeric programming. In contrast we have find that in some issues FORTRAN is more powerful than C in scientific and numerical programming specially in computational

FORTRAN and C have been compared, and their strengths and weaknesses with respect to scientific programming have been identified, the languages are evaluated on their performance.

for example

in + & - & * & / fortran is faster
in integer power computation fortran is faster A^2
in non-integer power C is faster A^2.33
in if endif control C is faster
in do for loop C is faster
in reading of data fortran is faster

in writing of data C is faster

jugghead June 26, 2009 08:47

See this answer:

Basically C/C++ can be as fast as Fortran as long as you carefully use the restrict keyword when defining pointers to arrays.

http://stackoverflow.com/questions/1...-than-c/499392

doorna February 10, 2012 17:33

plzz help me.
 
Dear all;
I am a super beginner in programming but i am super enthusiastic to know how to write codes.I know fundamental concepts of CFD.I wonder if any one knows of some books or sites which includes writing codes with c++ using CFD concepts.The only experience I had was writing code for lid driven cavity and it hasn't converge.It is like a dream for me write codes different problems!!!!!!!!!I am ready to do whatever it costs!
your answers are immensely appreciated in advance
best,
Doorna


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