next up previous contents
Next: Visualization of INDEPENDENT Directives Up: INDEPENDENT and Related Directives Previous: INDEPENDENT and Related Directives

The INDEPENDENT Directive

 

The INDEPENDENT directive can precede an indexed DO loop or FORALL statement. It asserts to the compiler that the iterations in the following DO loop or the operations in the following FORALL may be executed independently--that is, in any order, or interleaved, or concurrently--without changing the semantics of the program.

The INDEPENDENT directive precedes the DO loop or FORALL for which it asserts behavior, and is said to apply to that loop or FORALL. The syntax of the INDEPENDENT directive is

H501 independent-directiveis INDEPENDENT [ , new-clause ]
[ , reduction-clause ]
H502 new-clauseis NEW ( variable-name-list )
H503 reduction-clauseis REDUCTION ( reduction-variable-list )
H504 reduction-variableis array-variable-name
or scalar-variable-name
or structure-component

When applied to a DO loop, an INDEPENDENT directive is an assertion by the programmer that no iteration can interfere with any other iteration, either directly or indirectly. The following operations define such interference:

The interpretation of INDEPENDENT for FORALL is similar to that for DO: it asserts that no combination of the FORALL indices assigns to an atomic storage unit that is read by another combination. A DO and a FORALL with the same body are equivalent if they both have the INDEPENDENT directive. This is illustrated in Section 5.1.1.

If a procedure is called from within an INDEPENDENT loop or FORALL, then any local variables in that procedure are considered distinct on each call unless they have the SAVE attribute. This is consistent with the Fortran standard. Therefore, uses of local variables without the SAVE attribute in calls from different iterations do not cause interference as defined above.

Note that all these rules describe interfering behavior; they do not disallow specific syntax. Statements that appear to violate one or more of these restrictions are allowed in an INDEPENDENT loop, if they are not executed due to control flow. These restrictions allow an INDEPENDENT loop to be executed safely in parallel if computational resources are available. The directive is purely advisory and a compiler is free to ignore it if it cannot make use of the information.




next up previous contents
Next: Visualization of INDEPENDENT Directives Up: INDEPENDENT and Related Directives Previous: INDEPENDENT and Related Directives