CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Main CFD Forum (http://www.cfd-online.com/Forums/main/)
-   -   What is the differenc ebetween Fortran and C/C++?? (http://www.cfd-online.com/Forums/main/3403-what-differenc-ebetween-fortran-c-c.html)

J Keays. May 2, 2001 10:10

What is the differenc ebetween Fortran and C/C++??
 
Hi All, A straigh forward question if you, I'm sure. The reason I ask is that i ma oging doing a Ph.D in LES of Combustion...specifically Sub-grid scale models and I will be using Fortran. (Because my professor uses it!!). Anyway, I want to know if it would be in my interest to use C/C++ and if so, is it easy to convert it to Fortran to keep people smiling?? thank you.

Kike May 2, 2001 11:17

Re: What is the differenc ebetween Fortran and C/C
 
Dear John

Simple desicion algorithm

IF(you know FORTRAN) THEN

IF(you will use a code your professor had writen in FORTRAN) use FORTRAN

ELSE

if(you know C)

{

use C;

write your own code according your objectives;

}

else

learn C;

ENDIF

You will have to employ a lot of effort in programming LES and the language u use will be the less relevant part in your PhD. Fix your attention in Turbulent Combustion Physics, from the beggining, and you will have a really nice Thesis even programming in FORTRAN or C/C++. Good luck

Kike

J Keays. May 2, 2001 11:54

Re: What is the differenc ebetween Fortran and C/C
 
Hi Kike,

Thanks for the advise. I,m aware that the language of choice is less relevant than the actual physics. I'm looking at it from the point of view of a skills transfer in IT/Finance when I finish. Its a long way off, but I reckon C++ is more transferable and it would be good to have developed an experts use of the language. thanks again, John.

John C. Chien May 2, 2001 12:10

Re: What is the differenc ebetween Fortran and C/C
 
(1). Try to learn the language as early as possible. It takes time to do so. (2). Fortran is good for CFD. But CFD is becoming a complete process which also includes goemetry modeling, mesh generation, computer graphics. So, the solver part is becoming a smaller portion of the whole process. And C/C++ has been used extensively in those geometry/graphics related field. (3). Now you see, even in CFD, it is a good idea to know C/C++. And if you have to use PC for fluid flow simulation, then VC++ might be necessary in Window environment. (4). The trend is Fortran-> C/C++ -> VC++.

George Bergantz May 2, 2001 12:53

obvious- learn both!
 
Learn them both while you are still young and your mind is fresh. No doubt anything you learn today will be somewhat obsolete in 10 years.

Neither language is especially difficult.

J Keays. May 2, 2001 13:01

Re: obvious- learn both!
 
I guess its a good point. I just feel that 3-4 years using C++ to implement whatever models are necessary would be superior in terms of transferability to other industries and also with regard to what seems to be C++ better capabilities. (I take this on trust from my the guy I share an office with, who has used both for aero and solid acoustics.

andy May 2, 2001 14:12

Re: What is the differenc ebetween Fortran and C/C
 
If you are in a group it is far more important that you work with the group rather than doing your own thing on the side. If the group is using X then use X because your work will not cleanly feed the work of other members or vice-versa. Most group leaders will stop you from using Y anyway if it is going to be a problem for the group.

Having said that:

(1) Fortran is simpler to write and produces faster code than C/C++. This is important for big LES runs.

(2) Most serious numerical code is still in Fortran and likely to remain so in the near future (i.e. the length of a Ph.D.). Beyond that things are not so clear.

(3) It is almost impossible to convert a typical C++ program to Fortran without a complete restructuring/rewrite. This may not be the case for C but C is not so fashionable to use these days.

(4) Fortran is next to useless as a keyword on a CV for general IT/finance.

(5) There is large shift away from C/C++ in general IT/finance towards Java. There are a range of reasons for this but it generally boils down to the fact that a simple, relatively safe language with a massive set of libraries like Java can be used by a succession of relatively unskilled (cheap) programmers to produce reasonably maintainable code. An equivalent C++ programmer needs to be more skilled, more careful/disciplined and will produce more complicated code which is more difficult to maintain. A skilled C++ programmer will effectively use the low level C++ components to produce a custom higher level language to tackle the job in hand. This may work in a committed long term stable environment but not in the low skill, high turn over, general computing environment. (Of course, in the longer term someone will have to maintain the recent crop of C++ codes).

(6) Java is, unfortunately, a non-starter for numerical work because it is too slow. This cannot really be fixed because it is Java's safety which is the root cause. (Custom Java compilers have got within 50% of Fortran speed but it is unlikely they will get much closer - typical Java is around 1% of Fortran).

(7) Although widely used (presumably because of C) C++ is a truly weird programming language. It is a mixture of low level system constructs and an unnecessarily wide range of half implemented high level language features. It does not abstract the machine hence different machines have different primitives and therefore produce different answers. The specification is imprecise and allows, for example, implementation dependent use of temporaries. Since the construction of these can have side-effects it means different compilers that conform to the language and run on the same machine can still produce different answers. The difficulties of programming in C++ are widely recognised by both the believers and normal people. It is hard to believe that the major effort required to master C++ to the point where one can produce reasonably reliable programs is a sensible investment.


John C. Chien May 2, 2001 15:26

Re: What is the differenc ebetween Fortran and C/C
 
(1). It is important to remember that as soon as the code leaves the original author, it will become someone else's problem. So, the idea is to keep it as simple as possible. (2). And even in the C++, one still can use the old procedural approach, and keep the class/object to a minimum when not required. (3). JAVA is completely object-oriented. (4). Anyway, the new trend is to use "component-oriented model", so that component binary codes written in different languages can be packaged into components and used on multi-tier network, in a distributed fashion. The exchange of information is through the specification of the interfaces where the component functionality is exposed(methods or functions) and used. (5). This new trend on three-tier network should bring codes developed in different languages together and make the development and maintainance easier. (6). So, the idea to learn more languages is to know different ways to write codes.

Bubba May 2, 2001 16:32

Re: What is the differenc ebetween Fortran and C/C
 
A point was made that FORTRAN produced faster code than C++. Can you please direct me to your source.

I would be interested in seeing this for myself.

Thanks.

kalyan May 2, 2001 17:44

Re: What is the differenc ebetween Fortran and C/C
 
If you are going to write a C++ code that can be translated (almost line to line) to FORTRAN, it does not serve much purpose. If you are using OOPs or other concepts such as dynamic allocation/deallocation which are not supported by FORTRAN, it is perhaps worth looking into C++. A friend of mine uses FORTRAN 90 and from what I have seen of his work, it seems to be simple enough langauge with additional features like dynamic allocation which F77 does not support. I am stressing dynamic allocation because executables of combustion LES can get really huge and unless you have a big parallel machine, you may run out of space.

I do agree that it is perhaps worthwhile learning C++ when you just starting graduate school (before you start spending most of your work day trying to figure out why your combustion/LES models does not predict stuff as you expect them too). Based on observation, I have a feeling that C++ might help if you are using unstructured meshes (I do not know exactly why). But, as far as I know, the only LES people I know who use C++ for LES are Sandia Labs (MP_Salsa FEM based code), Pletcher's group at Iowa state, Gosman's group at Imperial College. It is perhaps a good idea to ask some one in one of these groups as to why they used C++ if you really need an answer.

Sebastien Perron May 2, 2001 21:21

Re: What is the differenc ebetween Fortran and C/C
 
The First codes for computational software I wrote were done in Fortran (it was about 7 years ago). But, since then, I quickly move to C++. There are many advantages:

1) If you use OOP programming in conjunction with UML modeling, you can quickly desing bug free programs that are easier to transfer to another person. Don't forget, if you PH.D is usefull, the code could possibly be used by another individual.

2) The objects that have been designed for one program can often be used for another project.

3) If the code is very well designed in C++, it can be faster than a Fortran code. With an approriate used of register variables and inline functions, code can be 25% faster than a Fortran code.I made tests with dot products and other vectors operations, the C++ is faster when well designed. It not truth that fortran is faster.

4) If you ever want to have a graphical interface on top of your program, it will be easier to do it with C++ than with fortran.

5) For the past year, I got some contracts with an Industry. Some of these contracts were related to porting old fortran to C++ in order to keep them working. And now, their begging me to work on a crazy project where the engineers did program the numerical stuff with fortran and the computer guys used C++ for the graphical interface. They are now runnig into all kind of troubles and they don't know what's going one.

6) The future is written in C++. Fortran is something of the past. If it wasn't of F90, it would be already dead.

Steve Amphlett May 3, 2001 04:41

Re: What is the differenc ebetween Fortran and C/C
 
Just to clarify, there is no such language as C/C++.

Kike May 3, 2001 05:27

Re: What is the differenc ebetween Fortran and C/C
 
Hi John

I read your messages and now I can see your "far future" interest. In your place I choise C++.

I desagree with Andy with respect to the "higher speed" of FORTRAN compared to C++. As Bubba, I would like to see this code, but you can do some test, as Sebastien did, to see the contrary.

The fact is that approximately the 90% of programmers community is working with C++ and only a few old professors and their students (I was included) still work on FORTRAN. The FORTRAN had became into an University tool to show the functionality of old programs from 80's.

As Sebastien wrote the software industry and almost every engineering company demand C, C++ or Java skills. Here in France and in Spain (where I live) you need to know C++ to contact the actual IT market.

I agree with JCChien and Sebastien; the portability of your code is a point to consider and you should have in mind that your work should be used by other colleagues in the future. I am sure they will program in C++, at least in any OOP language.

I assume that in your Univ. people work in Linux (or Unix), otherwise, try to use it. Windows uses a lot of resources in your machine so it makes the execution slower than in Linux. Besides it, as far as I know, there is no free compiler for FROTRAN or C in Windows, but you have the gcc, g77 or pg77 (all of them free and constantly upgraded) for Linux.

You will probably work in parallel enviroment (now or in a recent future) and MPI is only supported on WindowsNT(2000) with a lot of problems, nevertheless it is widely used in Linux (mostly in C++ than in FORTRAN).

During your PhD. try to forget the VC++, the VJava even the recent C# from Microsoft, after, when you finish, you will employ two weeks to upgrade your skills form C++ to VC++.

I hope it helps you, good luck (not with C++, I am sure it will very easy for you, but with Turbulent Combustion)

Kike

J Keays. May 3, 2001 06:22

Re: What is the differenc ebetween Fortran and C/C
 
Alright guys. Thanks for all the help. I know that C and C++ are different languages!! Anyway, the situation is I will probably have to use Fortran because my professor, his group and several other partners in the project all use it. So, I would like to extend my question to ask you guys what are the employment prospects outside the Engineering world for someone who has worked on parallel LES of Turbulent Combustion, specifically sug-grid scale turbulence? Thanks again, John.

andy May 3, 2001 06:27

Re: What is the differenc ebetween Fortran and C/C
 
My source is common sense and having a small understanding of how computers work. This can be obtained from an enormous range of sources if one damps down one's enthusiasm and questions what one is given (not mentioning any names at this point!).

The speed of Fortran over C/C++ arises because the Fortran optimizer can do a lot more optimising of array based operations than a C/C++ optimizer (i.e. rearrange the order of evaluation, pull things out of loops, tiling, etc...). This is because Fortran does not allow arrays to be invisibly overlapped whereas C does (often referred to aliasing in C) allowing the optimizer to deduce far more about data dependencies.

Note that you require an aggressive optimizer to get speed with Fortran. If your Fortran compiler is a reworked C compiler then Fortan-type optimizations are not going to be present. For example, comparing the speed of g77 and gcc on Linux is a fairly pointless exercise. It is also wise to use native compilers to get speed with Fortran since these tend to make most use of the go-faster goodies in the hardware.

There is some hope for C since C99 (or whatever it is called) has introduced a "not aliased" directive (I cannot recall the precise term). This, potentially, would allow C to achieve Fortran speeds if Fortran-type optimizations are introduced into the C compilers. This will not happen straightaway and not in all compilers but, with luck, the pressure of benchmark figures will force at least the native C99 compilers to improve array handling.

Unfortunately (typically?) the C++ standards committee initially rejected including the directive in the recent C++ standard. There will be pressure for C++ to conform more closely with C99 at the next round (good) but there is also pressure to give up C compatability in a desperate, late attempt to create a semi-sensible higher level language (why bother?).

If you want to know more read any book on optimization that at least considers non-C techniques.

Here is a typical link that someone posted to the forum the last time C/C++ or Fortran was discussed:

http://www.hpcf.cam.ac.uk/C_rant.html


clifford bradford May 3, 2001 13:38

Re: What is the differenc ebetween Fortran and C/C
 
"Skills transfer". Shit! if you're already contemplating that why get your PhD in CFD?

clifford bradford May 3, 2001 13:51

Re: What is the differenc ebetween Fortran and C/C
 
it's been my experience that if you have Fortran and C/C++ codes that do the same thing and they are compiled using similar options that the Fortran code can be optimised to run much faster. As Andy mentioned a good way to test this is to take code in Fortran and C/C++ and on the same machine (say an IBM RS6000) and compile them both with the respective IBM compilers using the same options (I say IBM because for the most part the options have the same names in both the Fortran and C/C++ compiler so you can be sure you're choosing the same thing) for example when I used to use RS6000s for speed I'd go with "-O4 -qstrict" or "-O3 -qstrict" I don't quite recall which. The fortran code would usually run faster. Also anecdotal evidence (including the Microsoft VC++ manual) indicates that using a lot of C++ object oriented features can slow your code. I'm not much of a C++ coder so I can't say.

John C. Chien May 3, 2001 17:33

Re: What is the differenc ebetween Fortran and C/C
 
(1). A degree is a degree, that's all. (2). Outside the engineering world, you don't need a degree, you need experience and knowledge about languages (programming or business). (3). If you start writing codes in C++, I am sure that the chances of getting a good job outside engineering is many many times higher. (4). A Phd dissertation is not very useful once you have the degree. So, try to learn as much as possible the computer related languages,and applications when you are still in the school. (make sure that you do practice the programming skill a lot.)

Sebastien Perron May 3, 2001 20:03

Re: What is the differenc ebetween Fortran and C/C
 
Usually, most of the time is spent in the linear equations solvers which used a lot of vector operations. If the C++ code and the Fortran code are written in the same manner, I agree that the fortran Code will run faster.

But, As I previously said, the C++ allows you to do things (such as function inlining and register variables) that will boost the performances of your code and surpass the Fortran code.

It is also true that if you use heritage with VC++ classes that use system interupts, your code will be slowed in a dramatic way.

Finaly, I must admit that it is science to write C++ code that run faster than a Fortran Code. But it can be done.


Greg Perkins May 3, 2001 20:41

Re: What is the differenc ebetween Fortran and C/C
 
Another thing to consider if you already have large amounts of code you don't want to port to another language is to use mixed language programming - in this case you can write the new parts of your program in C and still use original functions written in Fortran you get from your professor. I think C is generally the way forward, but as others comment, conceptually C and Fortran are 3rd generation languages and semantically almost identical. C++ is different of course being object orientated which uses different concepts - but not that hard.

Mixed mode development is harder to begin with though due to different calling conventions in C/Fortran.

Greg


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