Download PGI 5 User's Guide

Transcript
1
a(i,j) = x + c(i,j)
continue
There are a number of technical problems to be resolved in order to recognize expandable scalars
in non-innermost loops. Until this generalization occurs, scalars like x above will inhibit
parallelization of loops in which they are assigned. In the following example, scalar k is not
expandable, and it is not an accumulator for a reduction.
1
2
3
k = 1
do 3 i = 1, n
do 1 j = 1, n
a(j,i) = b(k) * x
k = i
if (i .gt. n/2) k = n - (i - n/2)
continue
If the outer loop is parallelized, conflicting values will be stored into k by the various processors.
The variable k cannot be made local to each processor because the value of k must remain
coherent among the processors. It is possible the loop could be parallelized if all assignments to k
are placed in critical sections. However, it is not clear where critical sections should be introduced
because in general the value for k could depend on another scalar (or on k itself), and code to
obtain the value of other scalars must reside in the same critical section.
In the example above, the assignment to k within a conditional at label 2 prevents k from being
recognized as an induction variable. If the conditional statement at label 2 is removed, k would be
an induction variable whose value varies linearly with j, and the loop could be parallelized.
2.6.3.3 Scalar Last Values
During parallelization, scalars within loops often need to be privatized; that is, each execution
thread will have its own independent copy of the scalar. Problems can arise if a privatized scalar
is accessed outside the loop. For example, consider the following loop:
for (i = 1; i<N; i++){
if( f(x[i]) > 5.0 ) t = x[i];
}
v = t;
The value of t may not be computed on the last iteration of the loop. Normally, if a scalar is
assigned within a loop and used following the loop, the PGI compilers save the last value of the
scalar. However, if the loop is parallelized and the scalar is not assigned on every iteration, it may
be difficult (without resorting to costly critical sections) to determine on what iteration t is last
36
Chapter 2