CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Main CFD Forum (http://www.cfd-online.com/Forums/main/)
-   -   C++ or Fortran for CFD solvers (http://www.cfd-online.com/Forums/main/112-c-fortran-cfd-solvers.html)

andy August 13, 1998 16:52

C++ or Fortran for CFD solvers
 
What are peoples experiences of coding CFD solvers in C++? Do they run at something approaching the speed of Fortran? Does the added abstraction really help in writing code faster and/or developing it once the code is written?

Andrzej Matuszkiewicz August 14, 1998 10:58

Re: C++ or Fortran for CFD solvers
 
Hi Andy,

There is at least one systematic study of C++ versus Fortran in CFD: H. Jiang & P.A. Forsyth, "Robust Linear and Nonlinear Strategies for Solution of the Transonic Euler Equations" Computers & Fluids Vol. 24, No. 7, pp. 753-770, 1995. It seems to me that it has been done before the Blitz library was available.

I think there is one major point for C++. The market for C++ compilers is much bigger that for Fortran, so C++ compilers improve their efficency very fast. It seems to me that makers of Fortran compilers cannot afford such an effort.

Andrzej

Igor Antropov August 14, 1998 14:39

Re: C++ or Fortran for CFD solvers
 
Well, yes, C compilers are getting better. However, most FORTRAN compilers are products of long evolution, and I do not think that C compiler developers will be able to catch up overnight. In addition, whenever you need some nontrivial mathematical routine to append to your CFD program, the chances are that it was written in FORTRAN rather than in C. So, the choice between FORTRAN and C for CFD, or another activity related to mathematics is like a choice between English and Esperanto. Surely Esperanto is better, but because of some strange reason everybody speaks English.

Anthony Iannetti August 14, 1998 15:49

Re: C++ or Fortran for CFD solvers
 
Andy,

Fortran is still the standard for CFD codes, or technical computing for a long time. As far as ease of use, whe programming in atechincal code, all anguages are about the same. Fortran 90 is able to address arrays much easier than Fortran 77 or the C languages. Fortran 90 is almost ojext oriented (it uses 'modules' instead of classes). The guys at Los Alamos told me in a seminar that it is very easy to work with. But for technical computing, speed is essential. Fortran is typically 5 times + faster than C++. This figure comes directly from NASA. It is also, from independant benhmarking, 1.5 to 2.0 times faster than C. Why, simply put frotran is designed to do one thing well - number crunching. C and C ++ are general languages. While fortran can do graphics (vis OpenGL). Must GUI's are written in C++. In this area, pheomenal speed is not important. This is when classes really help. Maybe C++ might improve, but I doubt it high performance fortran is becoming the defacto standard for CFD (it is based on F90). Also, F90 codes, becasuse of there implicit array operations, are able to be automatically parallelized much more effeciently than C++. Remember parallel programming is not a CFD standard.

Tony

Andrzej Matuszkiewicz August 14, 1998 17:45

Nothing lasts forever
 
"Everyone" spoke Latin in the Middle Ages, French in 19th century, English in 20th century... Nothing lasts forever.

Andrzej

Jonas Larsson August 14, 1998 19:07

Re: C++ or Fortran for CFD solvers
 
C++ is just as fast as F77 provided you write the code efficiently. The problem is that it is very easy to write inefficient code in C++ and you have to be very experienced to avoid pitfalls that will slow down your code considerably.

As I see it F77 (and also to some extent F90) helps the code developer to write efficient code, but doesn't give enough support to structure the code and make it easily maintainable.

C++ is the opposite, it helps the code developer to write well structured and easily maintainable code, but it doesn't help you to write efficient code.

Don't ask me what is best - depends on code complexity and how critical speed is I guess.

D.C August 15, 1998 05:54

Re: Nothing lasts forever
 
"Nothing, excepting Fortran and Unix!", will say "the Unix peoples". They do not remember perhaps, that 70 % of them Unix system is written in … Yes,in C language.

Dear Andrzej,

That was a good answer. Of course it is possible to write high performance codes in C of C++. Most of companies producing CAD-CAM, or CFD programs, have written or started to write these programs in C, or C++. At NASA there is an "important push" to move some of them old, good, reliable codes from Fortran to C. Why? Why, the CFD world moves from structured (or block structured) grid, finite differences (and I would say, Fortran) codes, toward the unstructured, flow-adaptive, finite volumes, large parallel (and here I would say C++, dynamic allocation and memory management) codes?

And, I would like to say a bit more (to put some gas on fire!) and I am sure that there will be a lot of peoples, "screaming" that it is impossible. Unfortunately for them, the future will be:

C++ language (and Java++ for Internet programming),

And …

Yes, Windows NT (here the Unix peoples will be very angry).

But, look who leads the software market! Fortunately, or not, in the next 10 years, everything will speak… windows. The new Windows NT 5.0 is coming! How the "Old, good Unix" can survive! I think he cannot!

Hey, Unix peoples don't take these words personally! This is the way it happens in history. That it is! This is the way these things move!

We already told them! And we tell them everyday!

Best regards. D.C.

I expect a lot of reactions! OK! This is good!


Stephane BARALON August 15, 1998 06:13

Re: Nothing lasts forever
 
Hi,

As you expected, you'll get some reaction.

I would like to emphasize that windows NT, OK, but Windows NT SERVERS: NO! The unix-based servers are still the best for large networks.

I must admit that I am not favorable to the idea of a Microsoft planet !

SINCERELY,


Stephane Baralon August 15, 1998 12:40

Re: C++ or Fortran for CFD solvers
 
Hi,

I also think that the C compilers still have some way to go before they catch up the performance of Fortran77 compilers ( F90 compilers are today not efficient enough: dixit a reknown workstation manufacturer: "There is no reason for a strictly f77 code to execute slower when compiled with an f90 compiler than with an f77 compiler. However, at this time(1/97), f90 generated code is often 2x (and sometimes worse) slower than f77 code".)

However, we should keep in mind that computer, as well as language performance are still strongly hardware dependent.

Another comment is that most of the CFD GURUS of today are from the fortran years. So wait for the next generation to hear gurus who would advise their colleagues to write their codes in C++ !!

David Hargreaves August 18, 1998 10:21

Re: Nothing lasts forever
 
Just one (major) point to make. Until NT becomes a multi-user operating system, every CFD user in a company will (potentially) require an expensive computational/graphics server on their desk. There is no such thing as job submission, CPU sharing or multiple logins on NT. Oh and 64-bit would be nice....

John C. Chien August 19, 1998 12:21

Re: C++ or Fortran for CFD solvers
 
Based on my personal experience, integrated CFD codes will be the only way to help the designer and spread the use of the CFD technology. In other word, the interactive, graphic interface should be part of the CFD code. In 80's, I have developed integrated CFD codes on mini-computer. I run the code interactively, with mesh display, solution display as part of CFD run. This was in a very big company environment. In late 80's, I was able to do the same on PC/486, using MS Fortran with color graphics. When you run the code, you don't have to worry about the graphic output. You can grap the frame and use the Windows paint program to do the editing, and send it to the printer right away. You don't have to worry about the pre- and post-processing at all. For me , the next step is to write the integrated CFD code in Windows , this can be done in either C or C++. With C++, you can re-use the codes. It is just like the animation world, you build the geometry, model, mesh, textures, lighting, animation sequence, in C or C++. In research environment, Fortran is straightforward. But, the number of people using Fortran will decrease in time. I have not written an integrated CFD code in C++ yet, but I have studied the Windows programming, C and C++ for eight years. My feeling is " a user-friendly CFD code should look like a Windows-based 3-D animation, or paint , or word processing program." ( if you can make it user-friendly using Fortran and OpenGl , I think, it will also serve the purpose.) Thank you for your time.

Clifford Arnold September 3, 1998 17:56

Re: C++ or Fortran for CFD solvers
 
This is a trick question. There are many issues. Several have been mentioned by others (e.g. ease of parallelization, maintenance costs of less structured code, speed of execution). Unfortunately the little actual data to substantiate any particular opinion is often out of date quickly.

I have heard from two different sources that major CFD solvers written in C or C++ are just as fast as FORTRAN due to huge improvements in the compilers' backend code generators (e.g. DEC compilers (FORTRAN, C and C++) for Windows95 and Windows/NT!!). I found this to be an amazing statement due to my strong bias towards FORTRAN for speed reasons.

And for those of you who think that may be true on PCs but not on UNIX boxes, recheck the performance numbers comparing these two platforms. Again it is shocking how fast those cheap little things are.

Depending on your compiler you may have a different experience, but I suspect any current advantage *you* see in FORTRAN in speed is only temporary. The fellow who said the money isn't being spent on FORTRAN is right. It hasn't been there for years. And there is data that other languages' compilers have already caught up.

From a code maintenance point of view and leveraging new programming resources, I believe the answer is C or C++ today and other languages in the future.


All times are GMT -4. The time now is 21:33.