Fortran vs. C for numerical work 
Author Message
 Fortran vs. C for numerical work

It is often stated that fortran is better than C for numerical work. I
am interested in compiling both the standard list of such arguments
and what any counterarguments might be.

Please email me directly. I will post a summary to the net when the
replies have stopped trickling in.

(I am interested in things like pointer aliasing, optimizer
assumptions, inlining ability etc., not language wars).

Thank you

Brian
--
       Brian Glendenning - National Radio Astronomy Observatory



Sun, 09 May 1993 13:33:42 GMT  
 Fortran vs. C for numerical work

Quote:

>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.

Quote:
>Brian
>--
>       Brian Glendenning - National Radio Astronomy Observatory


Guangliang He

                            Guangliang He





Mon, 10 May 1993 02:43:08 GMT  
 Fortran vs. C for numerical work

Quote:
(Guangliang He) 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.



Mon, 10 May 1993 06:08:16 GMT  
 Fortran vs. C for numerical work

Quote:

>It is often stated that Fortran is better than C for numerical work. I
>am interested in compiling both the standard list of such arguments
>and what any counterarguments might be.

Here are the reasons that FORTRAN has not been replaced by C:

 1) C is definitely for wizards, not beginners or casual programmers.
    Usually people who are heavily into numerical work are not hacker
    types.  They are mathematicians, scientists, or engineers.  They
    want to do calculations, not tricky pointer manipulations.
    FORTRAN's constructs are more obvious to use, while even simple
    programs in C tend to be filled with tricks.  Even the fundamental
    operation of reading input is tricky in C, as shown by the recent
    postings on scanf, gets, and fgets.

 2) FORTRAN is dangerous to use, but not as dangerous as C.  For
    instance, most FORTRAN compilers have subscript checking as an
    option, while I have never encountered a C compiler with this
    feature.  The ANSI standard for function prototypes will
    give C an edge over FORTRAN in parameter mismatch errors, but
    that improvement is relatively recent and not enforced yet.

 3) There is a large body of well tested mathematical packages available
    for FORTRAN, that are not yet available in C.  For example the
    IMSL package.  However, this situation is improving for C.

 4) FORTRAN still gives the option of using single precision floating
    calculations for speed and space optimizations, whereas C forces
    some calculations into double precision.

 5) Optimizers are a non issue, since FORTRAN optimizers can match
    C optimizers on numerical expressions.

The reasons that C should replace FORTRAN for numerical work:

 1) C allows recursive functions, whereas portable FORTRAN doesn't.
    Recursive functions can often solve a problem more clearly
    than iterative methods, even if they are usually less efficient.

 2) FORTRAN has no dynamic array allocation.  Although C has dynamically
    allocated arrays, they are not trivial to describe or allocate.
--


               Dept. of Computer Science / University of Manitoba
               Winnipeg, Manitoba, Canada  R3T 2N2 / (204) 275-6682



Mon, 10 May 1993 13:14:46 GMT  
 Fortran vs. C for numerical work

Quote:

>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.

this says nothing about the *language*, only the *compilers*. actually, it
may not be that suprising when u consider that the 6000 runs unix and unix
needs a good C compiler. IBM may have spent more time on the C compiler than
the fortran compiler, figuring that more people may use C on the box than
fortran. believe it or not, i have seen similar behavior on crays (cft77 vs
scc [actually vc at the time], though also by only a few percent).

this does say that this particluar code seems well suited for C on the 6000
today. it implies that C is not a bad language for numerical work, if
performance is the criterion.

-bill

--
Bill Rosenkranz            |UUCP: {uunet,texsun}!convex!c1yankee!rosenkra



Mon, 10 May 1993 16:40:33 GMT  
 Fortran vs. C for numerical work

Quote:

>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.)

Well sure, from what I can tell, the primary structures of C, Pascal,
and Fortran look pretty similar. After learning Fortran, C is coming
along pretty naturally. The pointers and structures and unions are
interesting new things, kinda like "Fortran with some bells and whistles".

--
Avery Ray Colter    {apple|claris}!netcom!avery  {decwrl|mips|sgi}!btr!elfcat
(415) 839-4567   "I feel love has got to come on and I want it:
                  Something big and lovely!"         - The B-52s, "Channel Z"



Mon, 10 May 1993 17:37:17 GMT  
 Fortran vs. C for numerical work

Quote:

>   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."

Actually this is an inversion rather than a paraphrase.  I recall it being
exactly the other way round:

 "We don't know what the numerical programming language of the year 2000
  will look like, but it will be called Fortran."

which seems all too distressingly plausible!

(Take that any way you like... :-)
--

  Univ. of Adelaide,  South Australia. | Phone:                +61 8 228 5412



Mon, 10 May 1993 20:47:05 GMT  
 Fortran vs. C for numerical work
Quote:

>The reasons that C should replace FORTRAN for numerical work:

> 1) C allows recursive functions, whereas portable FORTRAN doesn't.
>    Recursive functions can often solve a problem more clearly
>    than iterative methods, even if they are usually less efficient.

> 2) FORTRAN has no dynamic array allocation.  Although C has dynamically
>    allocated arrays, they are not trivial to describe or allocate.
>--

It should be mentioned however, that the proposed Fortran 90 standard
does have allocatable arrays and most current generation Fortran compilers
already either allow for this or can be trivially linked to C to do it.
There are also recursive Fortran compilers available now and (if I remember
right) this is a feature of Fortran 90, should we live so long as to
actually see the standard adopted.

John Prentice
Amparo Corporation



Tue, 11 May 1993 00:13:31 GMT  
 Fortran vs. C for numerical work
Another interesting point is that in studies done at Cray Research, they
found it took SIGNIFICANTLY longer for their programmers to learn C and the
number of errors generated in coding in C (as opposed to Fortran) was much
higher.  Anyone who has programmed in C should be familiar with that problem.
It is not a particularly straightforward language.  

I would also raise the point that neither Fortran nor C are really all that
great as scientific languages.  They are both old languages which lack alot
of the features one would like in a modern language, particularly in a
world where the future looks increasingly to be in parallelism.  I laughingly
agree that the scientific language of the future will be "called Fortran", but
I don't know that I necessarily believe it.  There is a whole generation
of programmers (and scientists) coming on line who don't particularly
pledge allegence to Fortran.  Also, the traditional argument for not
ever throwing anything away in Fortran (i.e., there are billions of dollars
worth of old Fortran codes around, which is true I admit) will cease to
be that significant I expect in the future as we move away from serial
machines and as we concede that there is a finite lifetime to codes, even
ones written in Fortran.  This, by the way, is written from the perspective of
a computational physicist who has authored two hydrodynamic codes, both of
which are on the order of 100,000 lines of code.  

John Prentice
Amparo Corporation
Albuquerque, NM



Tue, 11 May 1993 00:28:07 GMT  
 Fortran vs. C for numerical work

Quote:

>     The ANSI standard for function prototypes will
>     give C an edge over FORTRAN in parameter mismatch errors, but
>     that improvement is relatively recent and not enforced yet.

There are several checkers around for Fortran:  several Fortran "lint"
programs (a perennial topic in this newsgroup), PFORT, something in
ToolPack.

Quote:
>  3) There is a large body of well tested mathematical packages available
>     for FORTRAN, that are not yet available in C.

Given the existence of f2c, any math package available _in_ Fortran is
effectively available in C, and in UNIX and VMS at least, it isn't hard
to call anything that could have been called from Fortran from C.

Quote:
>  4) FORTRAN still gives the option of using single precision floating
>     calculations for speed and space optimizations, whereas C forces
>     some calculations into double precision.

This is not true of ANSI C, and many vendors provided something like
Sun's "-fsingle" as an option for years before that.  It is also worth
noting that on a number of machines, single-precision calculations are
not faster than double precision.

Quote:
>  1) C allows recursive functions, whereas portable FORTRAN doesn't.
>     Recursive functions can often solve a problem more clearly
>     than iterative methods, even if they are usually less efficient.

Solved in Fortran Extended.

Quote:
>  2) FORTRAN has no dynamic array allocation.  Although C has dynamically
>     allocated arrays, they are not trivial to describe or allocate.

Solved in Fortran Extended.  Some vendors have provided pointers of some
sort for several years, and it is easy to fake on some systems.
--
I am not now and never have been a member of Mensa.             -- Ariadne.


Tue, 11 May 1993 14:08:46 GMT  
 Fortran vs. C for numerical work

Quote:

>    ...Even the fundamental
>    operation of reading input is tricky in C, as shown by the recent
>    postings on scanf, gets, and fgets.

Actually, Fortran has much the same problems in this area:  the facilities
for formatted input make little provision for clean error recovery.  This
doesn't show up very much because the stereotypical use of Fortran is for
batch jobs, not interaction.

Quote:
> 2) FORTRAN is dangerous to use, but not as dangerous as C.  For
>    instance, most FORTRAN compilers have subscript checking as an
>    option, while I have never encountered a C compiler with this
>    feature.  The ANSI standard for function prototypes will
>    give C an edge over FORTRAN in parameter mismatch errors, but
>    that improvement is relatively recent and not enforced yet.

One might ask what compilers you are using.  C compilers have trouble doing
subscript checking because of the complexity of C pointers, but debugging
compilers/interpreters which do this checking *do* exist.  And there are
already many C compilers which implement prototypes.

Quote:
> 3) There is a large body of well tested mathematical packages available
>    for FORTRAN, that are not yet available in C.  For example the
>    IMSL package.  However, this situation is improving for C.

As others have mentioned, given f2c, this is a non-issue.  They are all
available in C now.  (Sometimes they run faster that way, too...!)

Quote:
> 4) FORTRAN still gives the option of using single precision floating
>    calculations for speed and space optimizations, whereas C forces
>    some calculations into double precision.

Not any more.
--
"I'm not sure it's possible            | Henry Spencer at U of Toronto Zoology



Wed, 12 May 1993 02:12:09 GMT  
 Fortran vs. C for numerical work

Quote:


> 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.

This probably has nothing to do with the merits of C versus Fortran and
has everything to do with the merits of the compilers involved.  In the
UNIX world C compilers are often optimized to a gnats posterior whereas
Fortran compilers are often relatively primitive.  The converse is true
in environments where Fortran is big and C is just another minor language.

Fundamentally Fortran compilers can be faster because the Fortran language
specification forbids aliasing (but makes the user responsible for
making sure that it is not present) whereas C has to deal with it.
--
Richard Harter, Software Maintenance and Development Systems, Inc.
Net address: jjmhome!smds!rh Phone: 508-369-7398
US Mail: SMDS Inc., PO Box 555, Concord MA 01742
This sentence no verb.  This sentence short.  This signature done.



Wed, 12 May 1993 14:57:35 GMT  
 Fortran vs. C for numerical work

Quote:

>The reasons that C should replace FORTRAN for numerical work:

3)  C has decent support for nontrivial data structures, while they are
sufficiently painful to emulate in Fortran that few Fortran programmers
even try.

Most really interesting algorithms are associated with interesting data
structures.



Wed, 12 May 1993 01:15:42 GMT  
 Fortran vs. C for numerical work

Quote:


>>It is often stated that Fortran is better than C for numerical work...
>It may not be true any more. A friend of mine brought a little fortran
>program ...
>the excutable from C is faster than the excutable from Fortran by a few percent

What we have here is an example of one program compiled by one FORTRAN
compiler and a translation of that program compiled by one C compiler.
Comparison of the execution speeds of the two programs on one machine
cannot lead to any valid conclusions about the relative utility of the
two languages for numerical work.

FORTRAN has a large body of standard libraries for numerical work whose
operation and reliability have been well-tested for many years.  This
cannot be said for C, although some multi-language evironments allow
such FORTRAN libraries to be called from C programs.

The utility of a language must be judged by more criteria than just
execution speed of one sample program.
--




Thu, 13 May 1993 01:41:07 GMT  
 
 [ 28 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Fortran vs. C for numerical work

2. Fortran vs. C for numerical work

3. Fortran vs. C for numerical work

4. C vs Fortran for numerical work

5. C vs Fortran for numerical work

6. Fortran vs. C for numerical work

7. Re : Fortran vs. C for numerical work

8. C++/FORTRAN for numerical work

9. Fortran vc. C for numerical work

10. Languages for Numerical Computation --- Was C vs FORTRAN

11. Different Numerical answers: VMS vs. Unix Fortran

12. Fortran vs C for numerical computation

 

 
Powered by phpBB® Forum Software