Xref: utzoo comp.lang.fortran:4207 comp.lang.c:34354 Path: utzoo!utgpu!watserv1!watmath!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!apple!sun-barr!newstop!texsun!vector!egsner!mic!convex!convex.COM From: patrick@convex.COM (Patrick F. McGehearty) Newsgroups: comp.lang.fortran,comp.lang.c Subject: Re: Fortran vs. C for numerical work (SUMMARY) Message-ID: <109378@convex.convex.com> Date: 28 Nov 90 16:20:43 GMT References: <9458:Nov2721:51:5590@kramden.acf.nyu.edu> <7097@lanl.gov> <17680:Nov2806:04:1090@kramden.acf.nyu.edu> Sender: news@convex.com Reply-To: patrick@convex.COM (Patrick F. McGehearty) Followup-To: comp.lang.fortran Organization: Convex Computer Corporation, Richardson, Tx. Lines: 38 In article <17680:Nov2806:04:1090@kramden.acf.nyu.edu> brnstnd@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.