Re: Improving multi-dimension array access performance



In article <ggo8ld$h12$1@xxxxxxxx>,
Glen Herrmannsfeldt <gah@xxxxxxxxxxxxxxxx> wrote:

In cases where it isn't possible, such as matrix multiply, which goes
through arrays in different directions,

I'm not exactly sure what you mean by "isn't possible", but the
following loop structure accomplishes a matrix-matrix product and
steps through all three arrays with the innermost loops
corresponding to the left-most index.

do i = 1, n1
do j = 1, n2
bji = b(j,i)
do k = 1, n3
c(k,i) = c(k,i) + a(k,j) * bji
enddo
enddo
enddo

I think the thing that some people forget about this operation is
that there are three do loops, which results in 6 (=3!) possible
loop structures. In other words, there isn't just one way to do the
operation. On some machines one loop order is best, on other
machines another loop order is best. The above loop structure
treats the operation as a series of matrix-vector products, so it is
one of the conceptually obvious ones. Of course, loop unrolling,
subblocking, strip mining, and all of the other optimization
techniques should still be used to optimize this operation, and when
those options are combined with the 6 possible loop structures,
there are a tremendous number of practical possibilities.

$.02 -Ron Shepard
.



Relevant Pages

  • Re: Improving multi-dimension array access performance
    ... loop structures. ... matrix-matrix product required going through arrays in different ... accumulated into a register rather than to a memory location. ... This same thing occurs in the above loop structure if the cand ...
    (comp.lang.fortran)
  • Re: Check if Record was Entered Today.
    ... When you want a loop structure to skip over something but still continue to ... echo 'I do not need to doStuff() on this item.'; ...
    (php.general)
  • Re: visual basic
    ... you can modify the loop conditions for both examples so that the end ... The use of either loop structure could affect both. ... Underline the word TILL it is used to denote that when the loop will be ... One of the loops execute WHILE ...
    (comp.lang.basic.visual.misc)
  • Re: Improving multi-dimension array access performance
    ... following loop structure accomplishes a matrix-matrix product and steps through all three arrays with the innermost loops corresponding to the left-most index. ...
    (comp.lang.fortran)
  • Re: Continue While statement VBSCRIPT
    ... executing other instrustions once one of my conditions gets true/False ... > LOOP ... GOTO terminal statement of this loop structure). ...
    (microsoft.public.scripting.vbscript)