[comp.lang.misc] Fortran and memory performance

gumby@Gang-of-Four.Stanford.EDU (David Vinayak Wallace) (01/21/90)

   Date: 20 Jan 90 21:02:15 GMT
   From: ruede@boulder.Colorado.EDU (Ulrich Ruede)

   - Machines with memory hierarchies (virtual memory or Cache) will work
     more efficiently. When processing the meshes (say for a relaxation pass)
     I usually access several components of a node at the same time;
     this data will typically reside on the same (or a few adjacent) memory
     pages.  A straightforward FORTRAN implementation would use separate
     arrays for each member of the structure, so that several pages must
     swapped in for accessing one single node. Simulating the C memory
     structure in FORTRAN would require use of EQUIVALENCE and be difficult
     to make portable.

Rubbish.  Depending on the size of your nodes, the number thereof, and
how  you exampine them, FORTRAN could be more efficient.

Consider this limiting case: your structures each take one page's
worth of storage.  Each bucket is a word long.  You only examine two
buckets of each structure, in roughly sequential order.

In the C case you could conceivably take a fault on every (or every
other) structure you look at.  For the fortran program, you'll only
take a fauly every n (where for my example n happens to be the number
of words in a page by coincidence).

Obviously there are several dimensions over which the behaviour will
vary.  But the example illustrates that C structs aren't inherently
more efficient in this regard.  And in fact this problem comes up
often when working with large datasets.

I'm no fortran fan, nor a C fan.