Fortran vs. C for numerical work

Paul Havlak paco at rice.edu
Thu Nov 22 09:08:16 AEST 1990


In article <21884 at orstcs.CS.ORST.EDU>, ghe at comphy.physics.orst.edu
(Guangliang He) writes:
|> In article <BGLENDEN.90Nov21003342 at mandrill.cv.nrao.edu>
bglenden at mandrill.cv.nrao.edu (Brian Glendenning) writes:
|> >
|> >It is often stated that Fortran is better than C for numerical work.
|> >[Some deleted text here]
|> 
|> It may not be true any more. A friend of mine brought a little fortran
|> program (It is two big do loops with some instrinsic function calculation in
|> the loop.) and the C translation of the fortran program. We compiled two
|> program on a IBM RISC System 6000/530 with xlc and xlf. To my surprise, the
|> excutable from C is faster than the excutable from Fortran by a few percent.

Presumably the Fortran-to-C translation preserved the array structure and 
indexing found in the original Fortran program.  A good compiler can optimize
Fortran, no matter what language it's written in.

But watch out if you use C in its full generality.  All but the simplest
pointers
will confuse a compiler and reduce its ability to optimize.  Heap-allocated 
dynamic data structures will reduce data locality and increase page faults.

To paraphrase Jack Schwartz:
"We don't know what the numerical programming language of the year 2000 will
be called, but it will look like Fortran."  (Well, at least the loops will.)

-----------
Paul Havlak
These are the opinions of a single grad student, 
working on compiler analysis of scientific programs.



More information about the Comp.lang.c mailing list