next up previous contents
Next: Input and Output Up: INDEPENDENT NEW Loops Previous: New Variables Example 1

 

New Variables Example 2

This example illustrates a situation when only the outermost loops can be executed independently.

    !HPF$ INDEPENDENT, NEW (i2)
    DO i1 = 1, n1
     !HPF$ INDEPENDENT, NEW (i3)
     DO i2 = 1, n2
      !HPF$ INDEPENDENT, NEW (i4)
      DO i3 = 1, n3
       DO i4 = 1, n4
        a(i1,i2,i3) = a(i1,i2,i3) &
          + b(i1,i2,i4)*c(i2,i3,i4)
       END DO
      END DO
     END DO
    END DO

Beginning at the innermost loop it is clear that a(i1,i2,i3) is assigned to n4 times during execution of the i4 loop. The value set on one iteration is used in the next. Clearly, due to the multiple assignments to a(i1,i2,i3), all iterations of the i4 loop cannot be performed at the same time! This innermost loop is therefore not independent. The next loop, however, is INDEPENDENT. There is no problem with a(i1,i2,i3) being assigned to on more than one iteration since now i3 is the index variable. The i3 loop is independent because we can perform all n3 instances of the i4 loop at the same time.

The i2 and i1 loops are clearly independent because again a(i1,i2,i3) is not assigned to on more than one iteration.

Return to corresponding overview page gif


next up previous contents
Next: Input and Output Up: INDEPENDENT NEW Loops Previous: New Variables Example 1

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.