Re: multidimensional array order in memory
- From: Gary Scott <garylscott@xxxxxxxxxxxxx>
- Date: Sat, 07 Feb 2009 09:43:29 -0600
On Feb 7, 2:39 am, Glen Herrmannsfeldt <g...@xxxxxxxxxxxxxxxx> wrote:You would think :)
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
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
DO 3 K=1,maxk
DO 2 J=1,maxj
DO 1 I=1,maxi
Is this aove definition more or less still the standard for modern
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?
mailto:garylscott@sbcglobal dot net
Fortran Library: http://www.fortranlib.com
Support the Original G95 Project: http://www.g95.org
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