Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!snorkelwacker.mit.edu!mintaka!ai-lab!life!burley From: burley@pogo.ai.mit.edu (Craig Burley) Newsgroups: comp.lang.fortran Subject: Re: Fortran vs. C for numerical work (SUMMARY) Message-ID: Date: 28 Nov 90 13:49:20 GMT References: <9458:Nov2721:51:5590@kramden.acf.nyu.edu> <7097@lanl.gov> <17680:Nov2806:04:1090@kramden.acf.nyu.edu> <1990Nov28.065242.10154@murdoch.acc.Virginia.EDU> Sender: news@ai.mit.edu Organization: /home/fsf/burley/.organization Lines: 44 In-reply-to: gl8f@astsun.astro.Virginia.EDU's message of 28 Nov 90 06:52:42 GMT In article <1990Nov28.065242.10154@murdoch.acc.Virginia.EDU> gl8f@astsun.astro.Virginia.EDU (Greg Lindahl) writes: In article <17680:Nov2806:04:1090@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: >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. Except that inside loops, the multiplication is strength-reduced to an addition. That's why flat arrays are faster than double-pointer arrays for so many applications. The totally flexible language would hide this little detail from the programmer and would pick the right one. If I have to choose, I'd use flat arrays in my numerical programs. If I have to use C, a few macros give me what I really want. Hmm, could you explain to me how to strength-reduce multiplication to addition for random references to array elements within loops, as in SUBROUTINE FOO(A) REAL A(37,103) INTEGER I,J DO I,1=100 DO J,1=100 A(SOMEFUNC(I),OTHERFUNC(J)) = 0. END DO END DO END where SOMEFUNC and OTHERFUNC may be external functions or statement functions with expressions sufficient to ensure that there is no linearity between their inputs (I and J) and their outputs (used as array indices)? Such an optimization would be highly useful, I think, in GNU Fortran! So do let me know. I thought each reference to an element in A would require a computation involving at least one multiplication. -- James Craig Burley, Software Craftsperson burley@ai.mit.edu