comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Performance of a loop
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Performance of a loop [message #27397 is a reply to message #27359] Mon, 22 October 2001 08:07 Go to previous message
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
Martin Downing wrote:
>
> Paul,
> Im curious, can you explain why your modification should run faster?

The array access indices are listed as: [i,j,k]

The original loop order was
>>> FOR i = init, limit, 1 DO BEGIN
>>> FOR j = init, limit, 1 DO BEGIN
>>> FOR k = init, limit, 1 DO BEGIN

I suggested changing it to:
>> FOR k = init, limit, 1 DO BEGIN
>> FOR j = init, limit, 1 DO BEGIN
>> FOR i = init, limit, 1 DO BEGIN

i.e. reversing the i and k looping. IDL is like fortran in that array numbers are stored
continguously in the order of i->j->k (opposite to C) so by looping over k as the innerloop,
the access speed may suffer in that rather than loading numbers from adjacent memory locations,
jumps over the i and j dimension would be required to load the next k-dimensioned number.
Depending on the size of the arrays, this could incolve a lot of memory copying/gymnastics ==
time hog. Others more knowledgable than me about hardware would now start talking about cache
lines, translation lookaside buffer misses and other computey-type esoterica.

The upshot: always try to access memory contiguously.

paulv

--
Paul van Delst Religious and cultural
CIMSS @ NOAA/NCEP purity is a fundamentalist
Ph: (301)763-8000 x7274 fantasy
Fax:(301)763-8545 V.S.Naipaul
[Message index]
 
Read Message
Read Message
Previous Topic: Re: Matching, Aligning, Affine Transform
Next Topic: ENVI regustration: poly/RST to shift/rotation

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 16:07:32 PDT 2025

Total time taken to generate the page: 0.00192 seconds