Technical data
80
Chapter 5: Fortran Enhancements for Multiprocessors
loop can write a value into a memory location that is read or written by any
other iteration of that loop. It is also all right if the same iteration reads
and/or writes a memory location repeatedly as long as no others do; it is all
right if many iterations read the same location, as long as none of them write
to it. In a Fortran program, memory locations are represented by variable
names. So, to determine if a particular loop can be run in parallel, examine
the way variables are used in the loop. Because data dependence occurs only
when memory locations are modified, pay particular attention to variables
that appear on the left-hand side of assignment statements. If a variable is
not modified, there is no data dependence associated with it.
The Fortran compiler supports four kinds of variable usage within a parallel
loop: SHARE, LOCAL, LASTLOCAL, and REDUCTION. If a variable is
declared as SHARE, all iterations of the loop use the same copy. If a variable
is declared as LOCAL, each iteration is given its own uninitialized copy. A
variable is declared SHARE if it is only read (not written) within the loop or
if it is an array where each iteration of the loop uses a different element of the
array. A variable can be LOCAL if its value does not depend on any other
iteration and if its value is used only within a single iteration. In effect the
LOCAL variable is just temporary; a new copy can be created in each loop
iteration without changing the final answer. As a special case, if only the
very last value of a variable computed on the very last iteration is used
outside the loop (but would otherwise qualify as a LOCAL variable), the
loop can be multiprocessed by declaring the variable to be LASTLOCAL.
The use of REDUCTION variables is discussed later.
It is often difficult to analyze loops for data dependence information. Each
use of each variable must be examined to see if it fulfills the criteria for
LOCAL, LASTLOCAL, SHARE, or REDUCTION. If all the variables
conform, the loop can be parallelized. If not, the loop cannot be parallelized
as it stands, but possibly can be rewritten into an equivalent parallel form.
(See “Breaking Data Dependencies” on page 85 for information on rewriting
code in parallel form.)
An alternative to analyzing variable usage by hand is to use PFA. This
optional software package is a Fortran preprocessor that analyzes loops for
data dependence. If it can determine that a loop is data-independent, it
automatically inserts the required compiler directives (see “Writing Parallel
Fortran” on page 71). If PFA cannot determine the loop to be independent, it
produces a listing file detailing where the problems lie.










