Highly Optimizable Subset of C (was: Fortran vs. C for numerical work)
Peter S. Shenkin
shenkin at cunixf.cc.columbia.edu
Sun Nov 25 07:17:31 AEST 1990
In article <1990Nov23.181209.26366 at zoo.toronto.edu> henry at zoo.toronto.edu (Henry Spencer) writes:
>In article <1990Nov22.051446.1871 at ccu.umanitoba.ca> salomon at ccu.umanitoba.ca (Dan Salomon) writes:
>> 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...!)
And sometimes they run a little bit slower, but they seem to run at
*approximately* the same speed. This raises the following questions.
The difficulty of optimizing C comes from C features (pointers) absent
in Fortran. It has been observed that C programs translated from Fortran
using f2c run about as fast as the Fortran versions, which seems to imply that
(1) such translations do not use the problematic C features, and (2) if
the probematic C features are avoided, C compilers optimize about as well
as Fortran compilers; in fact, much of the optimization goes on at the
intermediate code level, doesn't it?
Now, many proposals have been made to improve C optimization: the use
of "noalias", #pragmas, and so on. But the above observations would seem to
imply that if the programmer simply restricts him/herself to a Fortran-like
"highly optimizable subset" of C, then he/she can expect Fortran-like
performance out of any reasonably good C compiler.
Now the questions are:
(1) How true is this?
(2) Just what is this highly optimizable subset of C?
(3) Whose compilers do best at this?
Someone who could write guidelines for (2) and perform measurements of (3)
would be performing a great service to the community.
Just as programmers writing Fortran for vector machines have learned how
to write code so as to optimize automatic vectorization by vectorizing
Fortran compilers, so, similarly, programmers writing C for numerical
applications can learn to write code so as to make it easy for a C compiler
to optimize it. Now, some might as, "Why bother?" I.e., "If you're going to
restrict yourself to a Fortran-like subset of C, why not just use Fortran?"
The answer, of course, is that only the numerical part of the code -- and
most likely only a portion of the numerical part -- need be coded in
this manner. The rest can take full advantage of C's extra features. And
one need not be concerned with the non-portability of Fortran calls
from C routines, and vice-versa.
-P.
************************f*u*cn*rd*ths*u*cn*gt*a*gd*jb**************************
Peter S. Shenkin, Department of Chemistry, Barnard College, New York, NY 10027
(212)854-1418 shenkin at cunixf.cc.columbia.edu(Internet) shenkin at cunixf(Bitnet)
***"In scenic New York... where the third world is only a subway ride away."***
More information about the Comp.lang.c
mailing list