Parallel Programming Guide for HP-UX Systems

Troubleshooting
Misused directives and pragmas
Chapter 9 187
Misused directives and pragmas
Misused directives and pragmas are a common cause of wrong answers.
Some of the more common misuses of directives and pragmas involve the
following:
Loop-carried dependences
Reductions
Nondeterminism of parallel execution
Descriptions of and methods for avoiding the items listed above are
described in the sections below.
Loop-carried dependences
Forcing parallelization of a loop containing a call is safe only if the called
routine contains no dependences.
Do not assume that it is always safe to parallelize a loop whose data is
safe to localize. You can safely localize loop data in loops that do not
contain a loop-carried dependence (LCD) of the form shown in the
following Fortran loop:
DO I = 2, M
DO J = 1, N
A(I,J) = A(I+IADD,J+JADD) + B(I,J)
ENDDO
ENDDO
where one of IADD and JADD is negative and the other is positive.
You cannot safely parallelize a loop that contains any kind of LCD,
except by using ordered sections around the LCDs.
The MAIN section of the Fortran program below initializes A, calls CALC,
and outputs the new array values. In subroutine CALC, the indirect index
used in A(IN(I)) introduces a potential dependence that prevents the
compiler from parallelizing CALC’s I loop.
PROGRAM MAIN
REAL A(1025)
INTEGER IN(1025)
COMMON /DATA/ A