VAR x,a,b: grid OF REAL;
...
IF DIM(grid,2) IN {2,3} THEN x := a+b
END;
Figure 6 Data parallel instructionSo whenever a selection is performed, e.g. by an IF statement with vector condition, only those PEs are active during execution of the THEN branch, whose local condition evaluates to TRUE. A THEN branch or an ELSE branch will only be executed if the condition (or its negation, respectively) will be satisfied by at least one PE. Primarily, this has an effect on any scalar statements that may be in such a branch, since in this case they will be skipped. In the general case, when the condition evaluates to TRUE for some PEs, but evaluates to FALSE for some other PEs, then both THEN branch and ELSE branch will be executed subsequently (first THEN, afterwards ELSE) with the appropriate group of PEs being active (this also holds for any scalar statements that may be contained in these branches). If vector IF statements are nested, then in one of the inner branches only a subset of the PEs of the corresponding outer branch is active.
VAR x: grid OF INTEGER; ... IF x>5 THEN x := x - 3 ELSE x := 2 * xEND;
When entering a loop with vector condition (e.g. WHILE loop), only those PEs are active which satisfy the condition. In subsequent iterations of this loop, the number of PEs is always decreasing. The loop iterates until no PE is left to satisfy the loop condition (see the following example).
VAR x: grid OF INTEGER; ... WHILE x>5 DO x:= x DIV 2; END;
Other control structures, known from sequential Modula-2 may be used as well in vector context. The CASE-selection can be treated as a nested chain of IF-THEN-ELSIF-selections, while FOR- and REPEAT-loops can be regarded as modifications of a WHILE-loop. The parallel LOOP-EXIT construct differs from its sequential counterpart, for it has to specify the name of the selected configuration, e.g.:
LOOP OF grid DO ... IF x>0 THEN EXIT END; ... END; (* loop *)In case one would like to perform an operation on all PEs inside a nested selection or loop, the ALL block may be used to re-activate all PEs of a configuration.
IF x>0
THEN ... (* only grid PEs are active, which satisfy condition *)
ALL grid DO
... (* all grid PEs are active, regardless of condition *)
END
ELSE ... (* only grid PEs are active, which do not satisfy condition *)
END;