Next: Examples of INDEPENDENT
Up: Data Parallel Statements
Previous: Comments on Pure
The INDEPENDENT directive precedes the DO loop or FORALL for which it is asserting behavior, and is said to apply to that
loop or FORALL.
The syntax of the INDEPENDENT directive is
XBNF
independent-directive -to -rule
to to is INDEPENDENT [ , new-clause ]
new-clause -to -rule
to to is NEW ( variable-list )
XBNF
When applied to a DO loop, an INDEPENDENT directive is an
assertion by the programmer that no iteration can affect any other
iteration, either directly or indirectly. The following operations
define such interference:
- Any two operations that assign to the same atomic object (defined
in Section ) interfere with each other. (Note the
NEW clause below, however.)
- An operation that assigns to an atomic object interferes with any
operation that uses the value of that object. (Note the NEW
clause below, however.)
-
- Rationale.
These are the classic Bernstein [5] conditions to enable parallel execution.
Note that two assignments of the same value
to a variable interfere with each other and thus an INDEPENDENT
loop with such assignments is not HPF-conforming.
This is not allowed because such overlapping assignments are difficult to
support on some hardware, and because the given definition was felt to be
conceptually clearer.
Similarly, it is not
HPF-conforming to assert that assignment of multiple values to the same
location is INDEPENDENT, even if the program logically can accept
any of the possible values.
In this case, both the ``conceptually clearer'' argument and the desire
to avoid nondeterministic behavior favored the given solution.
(End of rationale.)
- Any transfer of control to a branch target statement outside the body
of the loop interferes with all other operations in the loop.
- Any execution of an EXIT, STOP, or PAUSE
statement interferes with all other operations in the loop.
-
- Rationale.
Branching (by GOTO or ERR= branches in I/O statements)
implies that some iterations of the loop are not executed, which is
drastic interference with those computations. The same is true for EXIT and the other statements.
Note that these conditions do not restrict procedure calls in INDEPENDENT loops, except to disallow taking alternate returns to
statements outside the loop.
(End of rationale.)
- A READ operation assigns to the objects in its input-item-list; a WRITE or PRINT operation uses the values of
the objects on its output-item-list. I/O operations may
interfere with other operations (including other I/O operations) as per
the conditions above.
- An internal READ operation uses its internal file; an
internal WRITE operation assigns to its internal file. These
uses and assignments may interfere with other operations as outlined
above.
- Any two file I/O operations except INQUIRE associated with the same
file or unit interfere with each other.
Two INQUIRE operations do not interfere with each other; however,
an INQUIRE operation interferes with any other I/O operation
associated with the same file.
-
- Rationale.
Because Fortran carefully defines the file position after a data transfer
or file positioning statement, these operations affect the
global state of a program. (Note that file position is defined even for
direct access files.)
Multiple non-advancing data transfer statements affect the file position
in ways similar to multiple assignments of the same value to a variable,
and is disallowed for the same reason.
Multiple OPEN and CLOSE operations affect the status of files
and units, which is another global side effect.
INQUIRE does not affect the file status, and therefore does not
affect other inquiries.
However, other file operations may affect the properties reported by INQUIRE.
(End of rationale.)
- Any data realignment or redistribution performed in the loop
interferes with any access to or any other realignment of the same data.
-
- Rationale.
REALIGN and REDISTRIBUTE may change the processor storing a
particular array element, which interferes with any assignment or use of
that element. Similarly, multiple remapping operations may cause the
same element to be stored in multiple locations.
(End of rationale.)
Note that all of these 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.
The NEW option modifies the INDEPENDENT
directive and all surrounding INDEPENDENT directives
by asserting that those assertions would be true if
new objects were created for the named
variables for each iteration of the DO loop.
Thus, variables named in
the new-clause behave as if they were private to the body of the
DO loop.
More formally, it
asserts that the remainder of program execution is unaffected if
all variables in the variable-list and any variables associated
with them were to become undefined immediately before execution of
every iteration of the loop, and also become undefined immediately
after the completion of each iteration of the loop.
- []Rationale.
NEW variables provide the means to declare temporaries in INDEPENDENT loops.
Without this feature, many conceptually independent loops would need
substantial rewriting (including expansion of scalars into arrays) to
meet the rather strict requirements described above.
Note that a temporary need only be declared NEW at the innermost
lexical level at which it is assigned, since all enclosing INDEPENDENT assertions must take that NEW into account.
Note also that index variables for nested DO loops must be declared
NEW; the alternative was to limit the scope of an index variable to
the loop itself, which changes Fortran semantics.
FORALL indices, however, are restricted by the semantics of the FORALL;
they require no NEW declarations.
(End of rationale.)
The interpretation of INDEPENDENT for FORALL is similar to
that for DO: it asserts that no combination of the indexes that
INDEPENDENT applies assigns to an atomic storage unit that is
read by another combination. (Note that an HPF FORALL statement or
construct does not allow exits from the construct, etc.)
A DO and a FORALL with the same body are equivalent if they both
have the INDEPENDENT directive.
This is illustrated in Section .
Next: Examples of INDEPENDENT
Up: Data Parallel Statements
Previous: Comments on Pure
paula@erc.msstate.edu
Thu Dec 8 16:17:11 CST 1994