Re: row vs. column-major-order
Dimiter "malkia" Stanev 05 Oct 2006 07:11 UTC
According to this article on Wikipedia, Fortran uses column-major-order:
http://en.wikipedia.org/wiki/Row-major_order
"Aubrey Jaffer" <xxxxxx@alum.mit.edu> wrote in
message news:20060517204956.7AEE91B77xxxxxx@home.voluntocracy.org...
> Whether array elements are stored in row- or column-major-order
> matters to efficient cache use when the array is scanned.
>
> I believe that Scheme array code would run faster in
> column-major-order than it does in row-major-order.
>
> The functions which enumerate each element of an array reverse the
> indexes for each element access:
>
> (define (ra2v dims idxs)
> (if (null? dims)
> (let ((val (apply array-ref ra (REVERSE idxs))))
> ...)
> (do ((idx (+ -1 (car dims)) (+ -1 idx)))
> ((negative? idx) vect)
> (ra2v (cdr dims) (cons idx idxs)))))
> (ra2v dims '())
>
> But in column-major order the reverse is done only once:
>
> (define (ra2v dims idxs)
> (if (null? dims)
> (let ((val (apply array-ref ra idxs)))
> ...)
> (do ((idx (+ -1 (car dims)) (+ -1 idx)))
> ((negative? idx) vect)
> (ra2v (cdr dims) (cons idx idxs)))))
> (ra2v (REVERSE dims) '())
>
> Is Fortran's using column-major-order related to this?
>
>