and where loop-associated-directive (end-loop-associated-directive) is a do (enddo), dosimd
(enddosimd), or simd (endsimd) directive.
DescriptionThe scan directive may appear in the body of a loop or loop nest associated with
an enclosing worksharing-loop, worksharing-loop SIMD, or simd construct, to specify that
a scan computation updates each list item on each loop iteration. The directive specifies that
either an inclusive scan computation is to be performed for each list item that appears in an
inclusive clause on the directive, or an exclusive scan computation is to be performed for
each list item that appears in an exclusive clause on the directive. For each list item for
which a scan computation is specified, statements that lexically precede or follow the directive
constitute one of two phases for a given logical iteration of the loop – an input phase or a scan
phase.
If the list item appears in an inclusive clause, all statements in the structured block that lexically
precede the directive constitute the input phase and all statements in the structured block that lexically
follow the directive constitute the scan phase. If the list item appears in an exclusive clause and the
iteration is not the last iteration, all statements in the structured block that lexically precede the directive
constitute the scan phase and all statements in the structured block that lexically follow the
directive constitute the input phase. If the list item appears in an exclusive clause and the
iteration is the last iteration, the iteration does not have an input phase and all statements that
lexically precede or follow the directive constitute the scan phase for the iteration. The input
phase contains all computations that update the list item in the iteration, and the scan phase
ensures that any statement that reads the list item uses the result of the scan computation for that
iteration.
The result of a scan computation for a given iteration is calculated according to the last generalized prefix
sum (PRESUMlast) applied over the sequence of values given by the original value of the list item prior to
the loop and all preceding updates to the list item in the logical iteration space of the loop. The operation
PRESUMlast( op, a1, …, aN ) is defined for a given binary operator op and a sequence of N values a1, …, aN
as follows:
if
N= 1,
a1
if
N> 1,
op(
PRESUMlast(op,
a1,
…,
aK),
PRESUMlast(op,
aL,
…,
aN)
),
where
1 ≤K+ 1 =L≤N.
At the beginning of the input phase of each iteration, the list item is initialized with the initializer value of
the reduction-identifier specified by the reduction clause on the innermost enclosing construct. The
update value of a list item is, for a given iteration, the value of the list item on completion of its input
phase.
Let orig-val be the value of the original list item on entry to the enclosing worksharing-loop,
worksharing-loop SIMD, or simd construct. Let combiner be the combiner for the reduction-identifier
specified by the reduction clause on the construct. And let uI be the update value of a list item for
iteration I. For list items appearing in an inclusive clause on the scan directive, at the beginning of the
scan phase for iteration I the list item is assigned the result of the operation PRESUMlast( combiner,
orig-val, u0, …, uI). For list items appearing in an exclusive clause on the scan directive, at the
beginning of the scan phase for iteration I= 0 the list item is assigned the value orig-val, and at the
beginning of the scan phase for iteration I> 0 the list item is assigned the result of the operation
PRESUMlast( combiner, orig-val, u0, …, uI-1).
RestrictionsRestrictions to the scan directive are as follows:
Exactly
one
scan
directive
must
appear
in
the
loop
body
of
an
enclosing
worksharing-loop,
worksharing-loop
SIMD,
or
simd
construct
on
which
a
reduction
clause
with
the
inscan
modifier
is
present.
A
list
item
that
appears
in
the
inclusive
or
exclusive
clause
must
appear
in
a
reduction
clause
with
the
inscan
modifier
on
the
enclosing
worksharing-loop,
worksharing-loop
SIMD,
or
simd
construct.
Cross-iteration
dependences
across
different
logical
iterations
must
not
exist,
except
for
dependences
for
the
list
items
specified
in
an
inclusive
or
exclusive
clause.
Intra-iteration
dependences
from
a
statement
in
the
structured
block
preceding
a
scan
directive
to
a
statement
in
the
structured
block
following
a
scan
directive
must
not
exist,
except
for
dependences
for
the
list
items
specified
in
an
inclusive
or
exclusive
clause.
Cross References
worksharing-loop
construct,
see
Section 2.9.2
on
page 288.