next up previous contents
Next: Forall Examples Up: Expressing Parallel Execution Previous: Data Parallel Execution

 

Forall Statement

FORALL statement is included in Fortran 95. Syntax:

 
FORALL(< forall-triplet-list >[,< scalar-mask >])&

< assignment-stmt >

It:

For example,

    FORALL (i=1:n,j=1:m,A(i,j).NE.0) &
           A(i,j) = 1/A(i,j)

The stated assignment is performed in parallel for all specified values of i and j for which the mask expression is .TRUE..

When used without the mask, the FORALL statement simply performs conceptually parallel assignment -- any assignment that can be expressed in array syntax can also be expressed by a FORALL statement (or construct). The FORALL statement can also be used to express parallel assignments which it is impossible or very tricky to code using Fortran 90 features. Note that although the index variables look like the DO loop equivalent -- the colons imply that this is array syntax.

If a mask is added, such as in the given example, FORALL can be made to resemble a WHERE statement. Indeed, the example could actually be expressed using a WHERE statement:

  WHERE ( A.NE.0 ) A = 1/A

Again, very complex masked assignments can be made syntactically simpler by the use of a masked FORALL statement.

The only functions that can be called from within a FORALL statement are PURE functions -- recent research (2/97) shows that the best results can be obtained by in-lining any such functions directly into FORALL. (It may be necessary to use a FORALL construct to do this.

Now try this question gif

Return to corresponding overview page gif




next up previous contents
Next: Forall Examples Up: Expressing Parallel Execution Previous: Data Parallel Execution

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