next up previous contents
Next: Execution Process Up: Forall Statement Previous: Forall Statement

 

Forall Examples

FORALL is more versatile than array assignment:

It would be very awkward to express the assignments given in the first two bullet points using only array syntax and intrinsic procedure calls. The first performs parallel assignment of a vector to the diagonal of a matrix and the second gives a loop which contains parallel assignment to a section of an array. Each time around the loop the section being assigned to grows in size. (Note that the DO loop here is still executed sequentially, it could be parallelised by prefixing it with a

 !HPF$ INDEPENDENT, NEW(i)

directive, [see later for a discussion of the INDEPENDENT directive,] or by using a nested FORALL construct:

FORALL (j = 1:n)
 FORALL (i=1:j) A(i,j) = B(i) ! triangular
END FORALL

The second bullet-point example shows how the FORALL indices can be used in the RHS expression. This is easy to perform in a sequential DO loop but is not easy to express in array syntax. This FORALL is also masked so that the diagonal elements remain unchanged. REAL is an intrinsic procedure (function) so by definition is PURE.

The third example again shows how PURE procedures can be used in a FORALL body. Here, SIN could be the Fortran 90 intrinsic function or it could be a user-defined PURE function.

The final bullet point presents an example of parallel array assignment using indirect addressing (vector subscripting). The use of the FORALL index variable in the RHS would make this assignment difficult to express using regular Fortran 90 syntax.

Return to corresponding overview page gif


next up previous contents
Next: Execution Process Up: Forall Statement Previous: Forall Statement

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.