C vs. FORTRAN

Tom Stockfisch tps at chem.ucsd.edu
Fri Aug 11 15:23:52 AEST 1989


In article <14014 at lanl.gov> jlg at lanl.gov (Jim Giles) writes:
>From article <14523 at bfmny0.UUCP>, by tneff at bfmny0.UUCP (Tom Neff):
>> [...]                            Software that works right, and early,
>> is more important that a shaved MIP.  [...]
> In that case, Fortran is certainly a better choice than C for most
> numerical computations.

I have to disagree.

> Fortunately, it also helps if you're after shaving a few MIPs as well.

That's not true on most of the machines I use.  In fact, for scientific
programming that uses a lot of integer operations, C is almost always
faster as well as more convenient because of built-in, portable bit
operators and fewer restrictions on what constitutes an integer.

> Consider, for example, a routine to do matrix multiply
> on arbitrary sized and shaped matrices - both C an Fortran require the
> programmer to express the iteration explicitly, but only C requires the
> index calculations to be done explicitly.

Not really.  You can either use a macro, such as

	vecFn( a, nrow, ncol )
		double	*a;
	#		define A( i, j )	a[ (i)*ncol + (j) ]
	{
		int	i, j;
		...
		A(i,j)
		...
	}

Or, better, use a storage allocator that returns a pointer to the
first element of an array of pointers, each of which point to a row
of your matrix.  Then you have

	vecFn( a, nrow, ncol )
		double	**a;	/* nrow X ncol pseudo-matrix */
	{
		int	i, j;
		...
		a[i][j];
	}


Numerical algorithms have both a speed complexity and memory complexity,
and portable storage allocation is a big win for numerical C programs.
It's a major headache to edit and recompile fortran programs every time
you want to change the size of your problem.  And if you don't change
it back downwards you wind up with a 1000X1000 matrix swapping to disk
when your calculating the 10X10 case.

Sparse matrices are also easier in C.

> C++ does better, but only if the programmer has implemented a class...

Actually, the major advantage of C++ for numerical programming is complex
numbers.  This is the only place I use fortran, as C++ is not yet universally
available.

>when will we see a Fortran++ ?

It would have to be called "      FORTRAN = FORTRAN + 1.0E+00".
I think its a bad idea to make a new language upwardly compatable
from the Original Language.  When will we see Fortran die and fade away?
-- 

|| Tom Stockfisch, UCSD Chemistry	tps at chem.ucsd.edu



More information about the Comp.lang.c mailing list