+---------------------------------Fortran 95---------------------------------+

The **FORALL** construct performs assignment to
groups of subobjects, especially array elements.

Unlike the **WHERE** construct, **FORALL** performs assignment to
array elements, array sections, and substrings. Also, each assignment
within a **FORALL** construct need not be conformable with the previous
one. The **FORALL** construct can contain nested **FORALL**
statements, **FORALL** constructs, **WHERE** statements, and
**WHERE** constructs.

+-----------------------------End of Fortran 95------------------------------+

+-------------------------------IBM Extension--------------------------------+

The **INDEPENDENT** directive specifies that each operation in
the **FORALL** statement or construct can be executed in any order
without affecting the semantics of the program. For more information on
the **INDEPENDENT** directive, see INDEPENDENT.

+----------------------------End of IBM Extension----------------------------+

+---------------------------------Fortran 95---------------------------------+

>>- >>- >>- |

`FORALL_construct_statement`- See FORALL (Construct) for syntax details.
`END_FORALL_statement`- See END (Construct) for syntax details.
`forall_body`- is one or more of the following statements or constructs:
`forall_assignment`**WHERE**statement (see WHERE)**WHERE**construct (see WHERE Construct)**FORALL**statement (see FORALL)**FORALL**construct

`forall_assignment`- is either
`assignment_statement`or`pointer_assignment_statement`

Any procedures that are referenced in a `forall_body` (including one
referenced by a defined operation or defined assignment) must be pure.

If a **FORALL** statement or construct is nested within a
**FORALL** construct, the inner **FORALL** statement or construct
cannot redefine any `index_name` used in the outer **FORALL**
construct.

Although no atomic object can be assigned to, or have its association
status changed in the same statement more than once, different assignment
statements within the same **FORALL** construct can redefine or
reassociate an atomic object. Also, each **WHERE** statement and
assignment statement within a **WHERE** construct must follow these
restrictions.

If a `FORALL_construct_name` is specified, it must appear in both
the **FORALL** statement and the **END FORALL** statement.
Neither the **END FORALL** statement nor any statement within the
**FORALL** construct can be a branch target
statement.

+-----------------------------End of Fortran 95------------------------------+

+---------------------------------Fortran 95---------------------------------+

- From the
**FORALL**Construct statement, evaluate the`subscript`and`stride`expressions for each`forall_triplet_spec`in any order. All possible pairings of`index_name`values form the set of combinations. For example, given the statement:FORALL (I=1:3,J=4:5)

The set of combinations of

`I`and`J`is:{(1,4),(1,5),(2,4),(2,5),(3,4),(3,5)}

The

**-1**and**-qnozerosize**compiler options do not affect this step. - Evaluate the
`scalar_mask_expr`(from the**FORALL**Construct statement) for the set of combinations, in any order, producing a set of active combinations (those that evaluated to`.TRUE.`). For example, if the mask (`I+J.NE.6`) is applied to the above set, the set of active combinations is:{(1,4),(2,5),(3,4),(3,5)}

- Execute each
`forall_body`statement or construct in order of appearance. For the set of active combinations, each statement or construct is executed completely as follows:`assignment_statement`-
Evaluate, in any order, all values in the right-hand side

`expression`and all subscripts, strides, and substring bounds in the left-hand side`variable`for all active combinations of`index_name`values.Assign, in any order, the computed

`expression`values to the corresponding`variable`entities for all active combinations of`index_name`values.INTEGER, DIMENSION(50) :: A,B,C INTEGER :: X,I=2,J=49 FORALL (X=I:J) A(X)=B(X)+C(X) C(X)=B(X)-A(X) ! All these assignments are performed after the ! assignments in the preceding statement END FORALL END

`pointer_assignment_statement`-
Determine, in any order, what will be the targets of the pointer assignment, and evaluate all subscripts, strides, and substring bounds in the pointer for all active combinations of

`index_name`values. If a target is not a pointer, determination of the target does not include evaluation of its value. Pointer assignment never`requires`the value of the righthand side to be determined.Associate, in any order, all targets with the corresponding pointer entities for all active combinations of

`index_name`values. **WHERE**statement or construct-
Evaluate, in any order, the control mask and pending control mask for each

**WHERE**statement,**WHERE**construct statement,**ELSEWHERE**statement, or masked**ELSEWHERE**statement each active combination of`index_name`values, producing a refined set of active combinations for that statement, as described in Interpreting Masked Array Assignments. For each active combination, the compiler executes the assignment(s) of the**WHERE**statement,**WHERE**construct statement, or masked**ELSEWHERE**statement for those values of the control mask that are true for that active combination. The compiler executes each statement in a**WHERE**construct in order, as described previously.INTEGER I(100,10), J(100), X FORALL (X=1:100, J(X)>0) WHERE (I(X,:)<0) I(X,:)=0 ! Assigns 0 to an element of I along row X only if ! element value is less than 0 and value of element ! in corresponding column of J is greater than 0 ELSEWHERE I(X,:)=1 END WHERE END FORALL END

**FORALL**statement or construct-
Evaluate, in any order, the

`subscript`and`stride`expressions in the`forall_triplet_spec_list`for the active combinations of the outer**FORALL**statement or construct. The valid combinations are the Cartesian product of combination sets of the inner and outer**FORALL**constructs. The`scalar_mask_expr`determines the active combinations for the inner**FORALL**construct. Statements and constructs for these active combinations are executed.! Same as FORALL (I=1:100,J=1:100,I.NE.J) A(I,J)=A(J,I) INTEGER A(100,100) OUTER: FORALL (I=1:100) INNER: FORALL (J=1:100,I.NE.J) A(I,J)=A(J,I) END FORALL INNER END FORALL OUTER END

+-----------------------------End of Fortran 95------------------------------+