Parallel Programming Guide for HP-UX Systems

Data privatization
Privatizing loop variables
Chapter 6 113
Here, the LOOP_PARALLEL directive is required to parallelize the I loop
because of the call to MFY. The X and Y arrays are in shared memory by
default. X and Z are not written to, and the portions of Y written to in the
J loop’s IF statement are disjoint, so these shared arrays require no
special attention. The local array XMFIED, however, is written to. But
because XMFIED carries no values into or out of the I loop, it is privatized
using LOOP_PRIVATE. This gives each thread running the I loop its own
private copy of XMFIED, eliminating the expensive necessity of
synchronized access to XMFIED.
Note that an LCD exists for XMFIED in the J loop, but because this loop
runs serially on each processor, the dependence is safe.
Denoting induction variables in parallel loops
To safely parallelize a loop with the loop_parallel directive or pragma,
the compiler must be able to correctly determine the loop’s primary
induction variable.
The compiler can find primary Fortran DO loop induction variables. It
may, however, have trouble with DO WHILE or customized Fortran loops,
and with all loop_parallel loops in C. Therefore, when you use the
loop_parallel directive or pragma to manually parallelize a loop other
than an explicit Fortran DO loop, you should indicate the loop’s primary
induction variable using the IVAR=
indvar
attribute to loop_parallel.
Example 6-3 Denoting induction variables in parallel loops
Consider the following Fortran example:
I = 1
C$DIR LOOP_PARALLEL(IVAR = I)
10 A(I) = ...
.
. ! ASSUME NO DEPENDENCES
.
I = I + 1
IF(I .LE. N) GOTO 10
The above is a customized loop that uses I as its primary induction
variable. To ensure parallelization, the LOOP_PARALLEL directive is
placed immediately before the start of the loop, and the induction
variable, I, is specified.
Example 6-4 Denoting induction variables in parallel loops
Primary induction variables in C loops are difficult for the compiler to
find, so