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

 

Forall Statement

FORALL statement is included in Fortran 95. 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

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.

Now try this question gif




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

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