Performance of a loop [message #27359] |
Wed, 17 October 2001 23:43  |
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  |
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
|
|
|