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 
Switch to threaded view of this topic Create a new topic Submit Reply
Performance of a loop [message #27359] Wed, 17 October 2001 23:43 Go to next message
azM is currently offline  azM
Messages: 8
Registered: October 2001
Junior Member
How can i speed up this procedure? It steps through a matrix of either
64x64x64, 128x128x128 or in the worst case 256x256x256.

<==BEGIN IDL==>
FOR i = init, limit, 1 DO BEGIN
FOR j = init, limit, 1 DO BEGIN
FOR k = init, limit, 1 DO BEGIN
X=img_a(i:kernel_dim+i,j:kernel_dim+j,k:kernel_dim+k)
Y=img_b(i:kernel_dim+i,j:kernel_dim+j,k:kernel_dim+k)
sign_prob_map=TM_TEST(X,Y)
spm_plot_statistic(i,j,k)= sign_prob_map(0)
spm_plot_significance(i,j,k)= sign_prob_map(1)
ENDFOR
ENDFOR
ENDFOR
<== END IDL ==>

Thanks in advance,

Bob
(B.C.Hamans<<at>>student.tue.nl)
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
  Switch to threaded view of this topic Create a new topic Submit Reply
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 11:42:42 PDT 2025

Total time taken to generate the page: 0.00534 seconds