Summary
The scan directive specifies that scan computations update the list items on each iteration of an
enclosing loop nest that is associated with a worksharing-loop, worksharing-loop SIMD, or simd
directive.
Syntax
The syntax of the scan directive and the loop body that contains it is as follows:
and where the containing loop body belongs to the innermost loop that is associated with the directive of an
enclosing for, forsimd, or simd construct.
The syntax of the scan directive and the loop body that contains it is as follows:
and where the containing loop body belongs to the innermost loop that is associated with the directive of an
enclosing do, dosimd, or simd construct.
Description
A scan directive is associated with the same worksharing-loop, worksharing-loop SIMD, or simd
directive as the associated loop to which its containing loop body belongs. The directive specifies that a scan
computation updates each list item on each logical iteration of the associated loops controlled by its
associated directive. 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 sequence that
lexically precede the directive constitute the input phase and all statements in the structured block sequence
that lexically follow the directive constitute the scan phase. If the list item appears in an exclusive
clause, all statements in the structured block sequence that lexically precede the directive constitute the scan
phase and all statements in the structured block sequence that lexically follow the directive constitute the
input phase. 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 list items that appear in an inclusive or exclusive clause may include array sections.
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 that appear 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 that appear 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).
For list items that appear in an inclusive clause, at the end of the enclosing worksharing-loop,
worksharing-loop SIMD, or simd construct, the original list item is assigned the private copy from the last
logical iteration of the loops associated with the enclosing construct. For list items that appear in an
exclusive clause, let L be the last logical iteration of the loops associated with the enclosing construct.
At the end of the enclosing construct, the original list item is assigned the result of the operation
PRESUMlast( combiner, orig-val, u0, …, uL).
Restrictions
Restrictions to the scan directive are as follows:
Exactly
one
scan
directive
must
be
associated
with
a
given
worksharing-loop,
worksharing-loop
SIMD,
or
simd
directive
on
which
a
reduction
clause
with
the
inscan
modifier
is
present.
The
loops
that
are
associated
with
the
directive
to
which
the
scan
directive
is
associated
must
all
be
perfectly
nested.
A
list
item
that
appears
in
the
inclusive
or
exclusive
clause
must
appear
in
a
reduction
clause
with
the
inscan
modifier
on
the
associated
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
sequence
that
precede
a
scan
directive
to
a
statement
in
the
structured
block
sequence
that
follows
a
scan
directive
must
not
exist,
except
for
dependences
for
the
list
items
specified
in
an
inclusive
or
exclusive
clause.
The
private
copy
of
list
items
that
appear
in
the
inclusive
or
exclusive
clause
may
not
be
modified
in
the
scan
phase.