Fortran vs. C for numerical work (SUMMARY)

Patrick F. McGehearty patrick at convex.COM
Thu Nov 29 03:20:43 AEST 1990


In article <17680:Nov2806:04:1090 at kramden.acf.nyu.edu> brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
...stuff deleted in interest of brevity...
>Huh? A double-pointer array, as we were discussing, is a
>single-dimensional array of pointers to single-dimensional arrays. To
>access a random element of the array takes two additions and two memory
>references. In contrast, to access a random element of a flat array
>takes two additions, a multiplication, and a memory reference. On most
>widely used machines, a multiplication is quite a bit slower than a
>memory reference, particularly a cached memory reference. That's why
>double-pointer arrays are better than flat arrays for so many
>applications.
>
>Fortran can't deal with a double-pointer array efficiently because it
>doesn't have pointers. Simulating pointers efficiently is what I was
>calling difficult. Do you disagree?
>
>---Dan

Actually, simulating pointers in Fortran is not very hard, just a bit
ugly.  First declare an array SPACE for all data that might be pointed
to.  Then access it as you please.  For example: VAL = SPACE(IPTR(I)) 
I'm not claiming its a wonderful approach, just doable.
I did it 17 years ago in FTN66 because that was the only efficient
compiler for the machine I was using.

While a single access to a random element in memory of a flat array
takes two additions, one multiply and a memory reference, an successive
access on a normal loop iteration only takes one addition and a memory
reference.  That is, if we save the address of a(i,j) in a register, then
computing the address of either a(i+1,j) or a(i,j+1) only takes
a single addition, assuming a rectangular array.  The double-pointer
array still takes two memory accesses and an addition.

Also, on leading edge machines, a multiplication is as fast or faster
than a memory reference, especially if you miss the cache.  As
killer micros continue to increase their clock rates, this phenomena
will spread.  However, double-pointer arrays still will be used
for sparse data.



More information about the Comp.lang.c mailing list