Interpreting the FORALL construct
- 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. In a forall_assignment if variable is allocatable, -qxlf2003=autorealloc will not cause variable to be deallocated and/or allocated.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 ELSEWHERE ! greater than 0. 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


