This is the holy war of holy wars. Let me try and start it off
rationally.
I've spent the last few years working on the POOMA framework, using
every trick in the book -- and many that aren't in any books -- to
build general purpose scientific class libraries for high performance
and parallelism. We're using expression templates, lazy evaluation,
cache optimizations, loop reorderings, the whole nine yards. My team
and I have worked with other folks, like Todd Veldhuizen of Blitz++
and Jeremy Siek of MTL, and while I obviously can't speak for them,
the opinions below reflect conversations with them and I'm pretty
confident of them.
The basic deal is that the languages are different. They were
conceived with different goals in mind and have different capabilities
as a result. Modern C++ can do a lot of the things that a decade ago
only made sense in FORTRAN, and modern FORTRAN can do some things that
decade ago didn't make any sense at all in FORTRAN.
There are many syntax differences. FORTRAN has many ugly aspects, and
C++ (particularly with templates) has its warts. To my eye C++ has
fewer ugly syntax things and is more convenient to do complex things
in. To some degree that is a matter of taste and the task you have to
do.
There are more substantive differences. Given the forum I'll hit the
things FORTRAN does well first since I think those are less well
understood.
If the only data structure you need is flat multidimensional arrays,
FORTRAN does a very good job out of the box. With FORTRAN 90 you get
array syntax (i.e. you can say A=B+C*D for whole arrays), which is
very convenient and very difficult to do well in C++ (trust me on
this). It is easy to match FORTRAN 77 arrays in C++, but FORTRAN 90
arrays are difficult to match. Not completely impossible, but it
really is a Don't Try This At Home Kids(tm) kind of thing. At this
point though you can pick up POOMA, Blitz or the MTL to do this stuff
for you in C++, depending on the mix of features you're looking for.
There is a semantic difference in passing arrays to subroutines in
FORTRAN compared to C++: In FORTRAN you are guaranteeing that they are
not aliased. This can a really big deal for the optimizer when doing
numeric intensive work, and is the primary remaining factor that makes
many FORTRAN programs faster than the equivalent C++ programs. There
are proposals to improve this situation in C/C++ (primarily the
restrict keyword at this point), but they are spottily implemented.
The alternative to something like restrict is a godlike global
optimizer that can figure out the aliasing, but that is way in the
future for other than toy problems at this point. The bottom line,
sadly enough, is that given comparably smart optimizers, under
circumstances that are pretty common in scientific computing, the
C/C++ equivalent to a FORTRAN program, will often not run as fast.
Depending on the architecture it may not be a big difference, but it
can be up to a factor of two on conventional workstations, and much
larger than that on vector machines.
That is something FORTRAN does well, and we need to be rational about
it and not be bigots.
If we grant that modern FORTRAN does arrays better, we then have to go
to the things that C++ does better.
C++ is vastly easier to use for making exensible libraries of all
kinds. That includes inheritance heirarchies (which you really can't
do in F90) and generic libraries (templates, which you can't do at all
in F90). This is a really big deal, particularly for large projects.
You can't do anything like the STL in FORTRAN.
With F77, if it does what you need out of the box, you're golden. If
you need 5% more, you're dead. There is a cliff at the edge of arrays
and it is a long way down.
With F90, if you need more, then in some cases you can put together
the data structures to do it. Those data structures are nowhere near
as flexible or powerful as in C++, but you have more tools available
than with F77, and the arrays are convenient out of the box.
C++ is a Swiss Army Knife(tm) with a vast number of tools in it. By
picking the appropriate tools you can do everything from device
drivers to databases to nuclear weapon simulations. It is also true
that if you pick inappropriate tools you will cut your hands off
before you know what happened. And there are so many tools and so
many completely different programming styles possible in C++ that it
is difficult to understand the tools well enough to keep from cutting
yourself.
Personally, I'll take that risk instead of the risk of there not being
any feasible way to do what I want, which is more likely for many many
problems with a language like FORTRAN.
-Steve Karmesin
p.s. Please folks, no jihads.
Cesare Padovani writes:
> Could someone tell me where I can find a comparison between Fortran & C++.
>
> Best regards. Cesare Padovani.
>
> --------------------- Object Oriented Numerics List --------------------------
> * To subscribe/unsubscribe: use the handy web form at
> http://oonumerics.org/oon/
> * If this doesn't work, please send a note to owner-oon-list@oonumerics.org
>
--------------------- Object Oriented Numerics List --------------------------
* To subscribe/unsubscribe: use the handy web form at
http://oonumerics.org/oon/
* If this doesn't work, please send a note to owner-oon-list@oonumerics.org
This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 03:20:10 EST