F90 Vs C++
F90 Vs C++
http://www.cts.com.au/compare.html
Below is a note I just sent to the chairman of a physics department which requires
freshmen to take a programming class offered by the engineering department. That
course has traditionally taught Fortran77, but there is now a push on from the engineering
school to switch to teaching C++. As usual, the arguments being mustered revolve around
criticisms of Fortran 77 by people who are too out of touch to know much of anything
about Fortran 90. In either case, I was asked by one of the senior physics faculty to
contribute my two cents worth about what language they should be teaching. The
appended note is the one I sent and it summarizes our corporate experience with C++ and
some of our feelings about Fortran 90. Others may find this interesting.
It was mentioned to me that the Engineering school is considering changing Eng 120 to
teach C++ instead of Fortran and that you were soliciting comments about this with
regard to physics students. Even though I am not associated with the university, I wanted
to contribute my thoughts, which come from a commercial as well as a research
perspective.
The main reason C++ has attracted the attention it has in the scientific community is
because Fortran 77 was a terribly outdated language. The many weaknesses of Fortran 77
were solved with Fortran 90 however. Fortran 90 has every feature in C that is important
to scientific programming and most of the features of an object oriented language (it
lacks only inheritance and that is likely going to be added in Fortran 2000). However
unlike C and C++, Fortran 90 is designed to generate executable codes that are highly
optimized and thus run extremely fast. An example is pointers. Pointers are integral to C
and C++ programming and because the compiler cannot determine whether a pointer is
aliased, it is impossible for it to determine interprocedural dependencies. The result is a
significant degradation in optimization and extremely slow execution speeds (for most
scientific codes, C and C++ generally produce code which is commonly an order of
magnitude slower than Fortran 90 codes, based on the benchmarks we and others have
done). Fortran 90 pointers are designed to give the functionality of pointers, but with
restrictions that eliminate issues such as aliasing. From a programming perspective
however, an even more important point is that Fortran 90 has more natural ways of
expressing the functionality that C and C++ require pointers to express. Because of this,
Fortran 90 is a more natural language to program in and the time required for debugging
codes is a fraction of that required by C and C++ (C++ is much worse that C, provided
you are really employing an OOPS paradigm, since you find yourself spending a lot of
debug time going up and down inheritance trees). Another important point is that the time
required to learn Fortran 90 is much less than the time to learn either C or C++.
Fortran 90 has another major advantage over C or C++. Modern scientific computing,
and computing in general, is moving toward the use of parallel computers. Even PCs and
workstations now come with multiple processors, so parallelism is something that
everyone from an accountant to a physicist is encountering now. A major problem in
programming parallel computers however is the linear memory model that is inherent to
all procedural programming languages, with the singular exception of Fortran 90. A
linear memory model is one that assumes that consecutive elements of an array are
consecutive in memory. This was a reasonable assumption on traditional computers, but
it is completely incorrect on a parallel computer. Only Fortran 90 has addressed this
problem and providing standardized language support for parallelism. This support
includes array syntax and many intrinsics for doing array operations varying from
reduction operations such as array sums to matrix operations. With the use of Fortran 90
operator overloading and polymorphism, one can significantly extend the number of
operations that avoid any reliance on the linear memory model. The fact that Fortran 90
moved away from a linear memory model is the main reason that it has become the base
for so many data parallel languages such as Vienna Fortran, Fortran D, CRAFT, and
High Performance Fortran. The availability of data parallel dialects of Fortran 90 is an
especially large factor in favor of Fortran 90. Compilers of High Performance Fortran, for
example, are now coming on the market for virtually every machine out there (including
networks of workstations) and writing parallel codes in this language is straightforward.
Of particular importance is that porting a Fortran 90 code to High Performance Fortran is
extremely straightforward and codes written in High Performance Fortran can be run
unaltered on a Fortran 90 compiler (with the exception of one HPF construct, the forall,
which is being put into Fortran 95).
My own opinion is that scientists today need to know more than one language or
computing paradigm. And I think it is entirely reasonable that students learn C++ before
they graduate, though even more important is that they learn how to program MATLAB
and a computer algebra system such as Maple or Macsyma. But the issue is what
freshmen should learn as their first language and for that I would recommend Fortran 90
hands down. It is a better language for scientific programming and is both easier to learn
and use than the alternatives. It is also much more likely to be the language students will
be employing in their jobs upon graduation and it is the most promising route currently
developing for the programming of parallel computers.
Dr. John K Prentice, Quetzal Computational Associates, 3455 Main Ave., Suite 4,
Durango, CO 81301-0201
Fax: 970-382-8981 E-mail:[email protected].