Re: Row major / column major [message #83016] |
Thu, 31 January 2013 15:53 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
markjamie@gmail.com writes:
> I can hear you all sigh already.... I know... We've all been here before... but after all my reading I'm still utterly confused.
>
> I need to loop over the large dimension of a 3 x very large array,let's say 3 x 1E9. Sadly, given the operation I'm performing, there's no easy way to get round the loop using histogram etc.
>
> To improve the loop efficiency should the array be defined as:
>
> Myarray = intarr(3,1E9)
>
> Or
>
> Myarray = intarr(1E9,3)
>
> Does it matter at all? Have I got totally the wrong idea with this?
It matters. A LOT!
You have GOT to make sure your loop matches the order in which adjacent
values are laid out in memory (which is row order). Transpose your array
to make it a (1e9,3) array and loop over the three rows, handling all
the values in the columns as you go. Outer loop: rows. Inner loop:
columns.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|