Technical data
82
Chapter 5: Fortran Enhancements for Multiprocessors
Example 4: Local Variable
DO I = 1, N
X = A(I)*A(I) + B(I)
B(I) = X + B(I)*X
END DO
In this loop, each iteration of the loop reads and writes the variable X.
However, no loop iteration ever needs the value of X from any other
iteration. X is used as a temporary variable; its value does not survive from
one iteration to the next. This loop can be parallelized by declaring X to be a
LOCAL variable within the loop. Note that B(I) is both read and written by
the loop. This is not a problem because each iteration has a different value
for I, so each iteration uses a different B(I). The same B(I) is allowed to be
read and written as long as it is done by the same iteration of the loop. The
loop can be run in parallel. Arrays A andB can be declared SHARE, while
variable I should be declared LOCAL or LASTLOCAL.
Example 5: Function Call
DO 10 I = 1, N
X = SQRT(A(I))
B(I) = X*C(I) + X*D(I)
10 CONTINUE
The value of X in any iteration of the loop is independent of the value of X in
any other iteration, so X can be made a LOCAL variable. The loop can be run
in parallel. Arrays A, B, C, and D can be declared SHARE, while variable I
should be declared LOCAL or LASTLOCAL.
The interesting feature of this loop is that it invokes an external routine, sqrt.
It is possible to use functions and/or subroutines (intrinsic or user defined)
within a parallel loop. However, make sure that the various parallel
invocations of the routine do not interfere with one another. In particular,
sqrt returns a value that depends only on its input argument, that does not
modify global data, andthat does not use static storage. We say that sqrt has
no side effects.
All the Fortran intrinsic functions listed in Appendix A of the Fortran 77
Language Reference Manual have no side effects and can safely be part of a
parallel loop. For the most part, the Fortran library functions and VMS
intrinsic subroutine extensions (listed in Chapter 4, “System Functions and










