HOME
| OPENMP API Specification: Version 5.1 November 2020

2.11.8  scan Directive

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

SVG-Viewer needed.

The syntax of the scan directive and the loop body that contains it is as follows:  

 
{ 
   structured-block-sequence 
   #pragma omp scan clause new-line 
   structured-block-sequence 
}  

where clause is one of the following:  

 
inclusive(list) 
exclusive(list)  

and where the containing loop body belongs to the innermost loop that is associated with the directive of an enclosing for, for simd, or simd construct.

SVG-Viewer needed.

SVG-Viewer needed.

The syntax of the scan directive and the loop body that contains it is as follows:  

 
structured-block-sequence 
!$omp scan clause 
structured-block-sequence  
where clause is one of the following:
 
inclusive(list) 
exclusive(list)  

and where the containing loop body belongs to the innermost loop that is associated with the directive of an enclosing do, do simd, or simd construct.

SVG-Viewer needed.

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:

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:

Cross References