HOME
| OPENMP API Specification: Version 5.0 November 2018

2.9.6  scan Directive

SummaryThe scan directive specifies that scan computations update the list items on each iteration.

Syntax

SVG-Viewer needed.

The syntax of the scan directive is as follows:  

 
loop-associated-directive 
for-loop-headers 
{ 
   structured-block 
   #pragma omp scan clause new-line 
   structured-block 
}  

where clause is one of the following:  

 
inclusive(list) 
exclusive(list)  

and where loop-associated-directive is a for, for simd, or simd directive.

SVG-Viewer needed.

SVG-Viewer needed.

The syntax of the scan directive is as follows:  

 
loop-associated-directive 
do-loop-headers 
   structured-block 
   !$omp scan clause 
   structured-block 
do-termination-stmts(s) 
[end-loop-associated-directive]  

where clause is one of the following:  

 
inclusive(list) 
exclusive(list)  

and where loop-associated-directive (end-loop-associated-directive) is a do (end do), do simd (end do simd), or simd (end simd) directive.

SVG-Viewer needed.

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:

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:

Cross References