[comp.lang.fortran] f2c for numerical Fortran conversion

john@ghostwheel.unm.edu (John Prentice) (12/05/90)

In talking with people via e-mail concerning the use of f2c to convert
Fortran mathematical routines to C, the primary concern seems to be in
the efficiency of the converted code.  It would be interesting to take
some generic math routine, say a code to calculate Bessel functions, and
run it through f2c.  Then do a speed comparison between the Fortran and C
versions using compilers that generate good code.  This sort of test
would answer alot of my concerns about whether f2c can do this kind of
conversion or whether the resulting code would require alot of rewriting.
I am not that good a C programmer, anyone else want to give it a try?  I
would be happy to provide a Fortran math routine.  Beyond that, has anyone
ever considered running an entire library (say SLATEC) through f2c and
then seeing if it still works.  Considering that these libraries often
won't even compile when moving them from compiler to compiler in Fortran,
I wonder how successful a simple f2c conversion would be.  Another point
that worries me in using any type of automatic Fortran to C converter.
Alot of these standard libraries have code in them which is rather
sensitive to the order of operations, the word length, etc...  How
well does something like f2c preserve the numerical properties of the
Fortran coding?  Could one feel confident about this point?  Perhaps
one of the f2c development people could speak to that question.

Thanks,

John Prentice
Amparo Corporation
john@unmfys.unm.edu

mwm@VACATION.VENARI.CS.CMU.EDU (Mark Maimone) (12/07/90)

Some info from David Gay of AT&T:
------------------------------------------------------------------------
From: dmg@research.att.com [David Gay]
Date: Wed, 5 Dec 90 09:07:18 EST

Concerning the efficiency of the C produced by f2c, whether a
Fortran program runs faster or slower when converted by f2c
depends both on the Fortran and C compilers involved and on
the program itself; the comparison can go either way.  (The
point of f2c is to allow using Fortran source on systems that
have a C but not a Fortran compiler and to allow portable
mixing of C and Fortran.)

> has anyone
> ever considered running an entire library (say SLATEC) through f2c and
> then seeing if it still works.

Yes (e.g., PORT3). RTFM.  [also MINOS and the smaller NAG library -mwm]

> How
> well does something like f2c preserve the numerical properties of the
> Fortran coding?

F2c obeys the Fortran 77 standard, at least when the
resulting C is compiled by an ANSI C compiler (which must
honor parentheses) or when -kr is specified (see the f2c man page).

-- Dave
------------------------------------------------------------------------

	You can find more descriptive information about f2c by reading Bell
Labs Computing Science Tech Report 149, available in postscript format
by anon-ftp from research.att.com, in /dist/f2c/f2c.ps.Z.  Or you can
request it by email by sending this message to netlib@research.att.com:

	send f2c.ps from f2c

	In writing f2c, we started with the source for the original f77.  Not a
good optimizing compiler, but one that has been in service for over a
decade.  We corrected several known (and some previously unrecognized)
bugs with f77 along the way.  Why not try running your favorite library
source and test suite through f2c?  Here's a repost of one set of
benchmarks taken two months ago by some other folks:

-------------------------------------------------------------------------------
From: jim@interet.UUCP (User)
Subject: f2c is almost great
Date: 1 Oct 90 17:13:16 GMT

Here are some f2c versus Fortran benchmarks.  They were provided
by Nhuan Doduc, Framentec-Cognitech, Paris, France.  The program
is a thermohydraulic model, uses double precision arithmetic,
is compute bound, uses negligible IO, and is only 2% vectorizable.

    R Values using f2c and Fortran (larger R is faster)
    ===================================================

Computer                 R f2c      R Fortran      Relative
--------                 -----      ---------      --------
Solbourne Series 5         235            265          89 %
Sun 4/110                   61             74          82
Sun 4/260                   81             95          85
Sun 4/20 SLC                93            103          90
Sun 4/60 SparcStation I    107            119          90
Sun 4/370                  164            234          70

Note that the f2c translation is about 84% as fast as Fortran.

Nhuan Doduc wrote me to say:
"I would suggest only 2 conclusions: (1) f2c is SOLID since the doduc source is
VERY UGLY (it has broken many compilers) and (2) the doduc is a good candidate
for evaluating the progress of the work done on f2c, that is if f2c workers
want to improve their product."

Jim Ahlstrom         uunet!interet!jim
Nhuan Doduc          ndoduc@framentec.fr or ndoduc@cognitech.fr
-------------------------------------------------------------------------------
----------------------------------------------------------------------
Mark Maimone				phone: (412) 268 - 7698
Carnegie Mellon Computer Science	email: mwm@cs.cmu.edu
grad student, vocal jazz and PDQ Bach enthusiast