Technical data

86
Chapter 5: Fortran Enhancements for Multiprocessors
This is the same as Example 6 in Writing Parallel Fortran on page 71. Here,
INDX has its value carried from iteration to iteration. However, it is possible
to compute the appropriate value for INDX without making reference to any
previous value:
C$DOACROSS LOCAL (I, INDX)
DO I = 1, N
INDX = (I*(I+1))/2
A(I) = B(I) + C(INDX)
END DO
In this loop, the value of INDX is computed without using any values
computed on any other iteration. INDX can correctly be made a LOCAL
variable, and the loop can now be multiprocessed.
Example 2: Indirect Indexing
DO 100 I = 1, N
IX = INDEXX(I)
IY = INDEXY(I)
XFORCE(I) = XFORCE(I) + NEWXFORCE(IX)
YFORCE(I) = YFORCE(I) + NEWYFORCE(IY)
IXX = IXOFFSET(IX)
IYY = IYOFFSET(IY)
TOTAL(IXX, IYY) = TOTAL(IXX, IYY) + EPSILON
100 CONTINUE
It is the nal statement that causes problems. The indexes IXX and IYY are
computed in a complex way and depend on the values from the IXOFFSET
and IYOFFSET arrays. We do not know if TOTAL (IXX,IYY) in one iteration
of the loop will always be different from TOTAL (IXX,IYY) in every other
iteration of the loop.
We can pull the statement out into its own separate loop by expanding IXX
and IYY into arrays to hold intermediate values: