next up previous contents
Next: New Variables Example 2 Up: INDEPENDENT NEW Loops Previous: INDEPENDENT NEW Loops

 

New Variables Example 1

Consider,

    DO i = 1, n
     DO j = 1, m
      x = A(j)
      y = B(j)
      C(i,j) = x+y
     END DO
    END DO

with a nested loop such as this, it is the inner loops that must be examined first. Inspection of the j loop reveals that if copies were made of x and y for each iteration the loop would be INDEPENDENT. In order to parallelise, the directive:

  !HPF$ INDEPENDENT, NEW (x,y)

should prefix the inner loop.

Attention can now turn to the outermost loop. We could perform all the i iterations at the same time if there was a separate DO j loop for each iteration. Specifying j to be a NEW variable would do exactly this, viz:

    !HPF$ INDEPENDENT, NEW (j)
    DO i = 1, n
     !HPF$ INDEPENDENT, NEW (x,y)
     DO j = 1, m
      x = A(j)
      y = B(j)
      C(i,j) = x+y
     END DO
    END DO

After the loop x, y and j will have an undetermined value so cannot be used before being assigned a new value. (In regular Fortran they could be.)

 

Looking at the outermost leaves of Figure 39 will illustrate what can be performed in parallel. It can be seen that all tex2html_wrap_inline23874 iterations can be performed independently. There is no interaction between any iterations.

   figure15711
Figure 39: Visualisation of Double Nested Independent New Loop

Now try this question gif


next up previous contents
Next: New Variables Example 2 Up: INDEPENDENT NEW Loops Previous: INDEPENDENT NEW Loops

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 15:03:35 GMT 1996
Not for commercial use.