next up previous contents
Next: Pure Procedures Up: Data Parallel Execution Previous: Do-loops and Forall Statements

 

Forall Construct

The FORALL construct, which is also in Fortran 95, is very similar to the FORALL statement except that the indices and mask can be used to control more than one parallel assignment (a bit like the WHERE construct). As well as containing regular assignment statements, the body of a FORALL may also contain a further FORALL block or a WHERE block. This can lead to mind-bendingly complex assignments being expressed very concisely!

It has the following syntax:

 
FORALL( tex2html_wrap_inline21746  forall-triplet-list  tex2html_wrap_inline21748 [, tex2html_wrap_inline21746  scalar-mask  tex2html_wrap_inline21748 ])

tex2html_wrap_inline21746  assignment-stmt tex2html_wrap_inline21748

....

END FORALL

For example,

    FORALL (i=1:n:2, j=n:1:-2, A(i,j).NE.0)
           A(i,j) = 1/A(i,j) ! s1
           A(i,i) = B(i)     ! s2
    END FORALL

s1 executed first followed by s2

Can also nest FORALL s,

    FORALL (i=1:3, j=1:3, i>j)
     WHERE  (ABS(A(i,i,j,j)) .LT. 0.1) A(i,i,j,j) = 0.0
     FORALL (k=1:3, l=1:j, k+l>i) A(i,j,k,l) = j*k+l
    END FORALL

The two examples given here demonstrate a FORALL containing two assignments and a FORALL containing nested WHERE and FORALL statements.

Now try this question gif


next up previous contents
Next: Pure Procedures Up: Data Parallel Execution Previous: Do-loops and Forall Statements

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 15:03:35 GMT 1996
Not for commercial use.