Parallel Programming Guide for HP-UX Systems

Troubleshooting
Misused directives and pragmas
Chapter 9 189
values of the elements of JA never coincide with the values of I.
Assuming that they might collide, the compiler conservatively avoids
parallelizing the loop.
DO I = 1,100
JA(I) = I + 10
ENDDO
DO I = 1, 100
DO J = I, 100
A(I) = A(I) + B(J) * C(J) !LINE 6
A(JA(J)) = B(J) + C(J) !LINE 7
ENDDO
ENDDO
NOTE In this example, as well as the examples that follow, the
apparent dependence becomes real if any of the values of
the elements of JA are equal to the values iterated over by
I.
A no_loop_dependence directive or pragma placed before the J loop tells
the compiler that the indirect subscript does not cause a true
dependence. Because reductions are a form of dependence, this directive
also tells the compiler to ignore the reduction on A(I), which it would
normally handle. Ignoring this reduction causes the compiler to generate
incorrect code for the assignment on line 6. The apparent dependence on
line 7 is properly handled because of the directive. The resulting code
runs fast but produces incorrect answers.
To solve this problem, distribute the J loop, isolating the reduction from
the other statements, as shown in the following Fortran example:
DO I = 1, 100
DO J = I, 100
A(I) = A(I) + B(J) * C(J)
ENDDO
ENDDO
C$DIR NO_LOOP_DEPENDENCE(A)
DO I = 1, 100
DO J = I, 100
A(JA(J)) = B(J) + C(J)
ENDDO
ENDDO