Re: multidimensional array order in memory



rusi_pathan wrote:

On Feb 7, 2:39 am, Glen Herrmannsfeldt <g...@xxxxxxxxxxxxxxxx> wrote:

Terence wrote:

Given an array X(I,J,K), I was "brought uo" on the rule that arrays
are stored in column-major order; i.e. that the left-most index
changed most rapidly in passing memory-sequentially over the array in
memory.
And this implies it is slightly faster to access locations (fewer
computations) if a nest of three loops has the I loop K inside the J
loop, inside the K loop:-

In the old days it may have been slightly faster. With cache on
current machines it can make a very significant difference.
With virtual storage and large arrays it can make a
huge difference.




DO 3 K=1,maxk
DO 2 J=1,maxj
DO 1 I=1,maxi
...
1 CONTINUE
2 CONTINUE
3 CONTINUE

Is this aove definition more or less still the standard for modern
Fortran?

It is still that way.


Cant modern compilers figure that out automatically meaning I write
straightforward code (K inside J inside I) and the compilers change
the order minimizing cache miss?
You would think :)

--

Gary Scott
mailto:garylscott@sbcglobal dot net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

If you want to do the impossible, don't hire an expert because he knows it can't be done.

-- Henry Ford
.



Relevant Pages

  • Re: multidimensional array order in memory
    ... are stored in column-major order; ... changed most rapidly in passing memory-sequentially over the array in ... computations) if a nest of three loops has the I loop K inside the J ... In the old days it may have been slightly faster. ...
    (comp.lang.fortran)
  • multidimensional array order in memory
    ... Given an array X, I was "brought uo" on the rule that arrays ... are stored in column-major order; ... computations) if a nest of three loops has the I loop K inside the J ... I just added an index entry to the rule paragraph. ...
    (comp.lang.fortran)
  • Re: multidimensional array order in memory
    ... are stored in column-major order; ... computations) if a nest of three loops has the I loop K inside the J ... hard to notice unless you had addresses of array elements. ... programs actually compute the group average after each ROW, ...
    (comp.lang.fortran)
  • RE: Error 3021
    ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)
  • RE: Error 3021
    ... Kevin Backmann ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)