HOME
| OPENMP API Specification: Version 5.0 November 2018

2.9.1  Canonical Loop Form

SVG-Viewer needed.

The loops associated with a loop-associated directive have canonical loop form if they conform to the following:



for (init-expr; test-expr; incr-expr) structured-block


init-expr One of the following:
var = lb
integer-type var = lb
random-access-iterator-type var = lb
pointer-type var = lb
test-expr One of the following:
var relational-op b
b relational-op var
incr-expr One of the following:
++var
var++
- - var
var - -
var += incr
var - = incr
var = var + incr
var = incr + var
var = var - incr
var One of the following:
  A variable of a signed or unsigned integer type.
  For C++, a variable of a random access iterator type.
  For C, a variable of a pointer type.
This variable must not be modified during the execution of the for-loop other than in incr-expr.
relational-op One of the following:
<
<=
>
>=
!=
lb and b Expressions of a type compatible with the type of var that are loop invariant with respect to the outermost associated loop or are one of the following (where var-outer, a1, and a2 have a type compatible with the type of var, var-outer is var from an outer associated loop, and a1 and a2 are loop invariant integer expressions with respect to the outermost loop):
var-outer
var-outer + a2
a2 + var-outer
var-outer - a2
a2 - var-outer
a1 * var-outer
a1 * var-outer + a2
a2 + a1 * var-outer
a1 * var-outer - a2
a2 - a1 * var-outer
var-outer * a1
var-outer * a1 + a2
a2 + var-outer * a1
var-outer * a1 - a2
a2 - var-outer * a1
incr An integer expression that is loop invariant with respect to the outermost associated loop.


SVG-Viewer needed.

SVG-Viewer needed.

The loops associated with a loop-associated directive have canonical loop form if each of them is a do-loop that is a do-construct or an inner-shared-do-construct as defined by the Fortran standard. If an end do directive follows a do-construct in which several loop statements share a DO termination statement, then the directive can only be specified for the outermost of these DO statements.

The do-stmt for any do-loop must conform to the following:



DO [ label ] var =lb ,b [ ,incr ]


var A variable of integer type.
lb and b Expressions of a type compatible with the type of var that are loop invariant with respect to the outermost associated loop or are one of the following (where var-outer, a1, and a2 have a type compatible with the type of var, var-outer is var from an outer associated loop, and a1 and a2 are loop invariant integer expressions with respect to the outermost loop):
var-outer
var-outer + a2
a2 + var-outer
var-outer - a2
a2 - var-outer
a1 * var-outer
a1 * var-outer + a2
a2 + a1 * var-outer
a1 * var-outer - a2
a2 - a1 * var-outer
var-outer * a1
var-outer * a1 + a2
a2 + var-outer * a1
var-outer * a1 - a2
a2 - var-outer * a1
incr An integer expression that is loop invariant with respect to the outermost associated loop. If it is not explicitly specified, its value is assumed to be 1.


SVG-Viewer needed.

The canonical form allows the iteration count of all associated loops to be computed before executing the outermost loop. The incr and range-expr are evaluated before executing the loop-associated construct. If b or lb is loop invariant with respect to the outermost associated loop, it is evaluated before executing the loop-associated construct. If b or lb is not loop invariant with respect to the outermost associated loop, a1 and/or a2 are evaluated before executing the loop-associated construct. The computation is performed for each loop in an integer type. This type is derived from the type of var as follows:

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

The behavior is unspecified if any intermediate result required to compute the iteration count cannot be represented in the type determined above.

There is no implied synchronization during the evaluation of the lb, b, or incr expressions. It is unspecified whether, in what order, or how many times any side effects within the lb, b, or incr expressions occur.

SVG-Viewer needed.

Note – Random access iterators are required to support random access to elements in constant time. Other iterators are precluded by the restrictions since they can take linear time or offer limited functionality. The use of tasks to parallelize those cases is therefore advisable.

SVG-Viewer needed.

SVG-Viewer needed.

A range-based for loop that is valid in the base language and has a begin value that satisfies the random access iterator requirement has canonical loop form. Range-based for loops are of the following form:

for (range-decl: range-expr) structured-block

The begin-expr and end-expr expressions are derived from range-expr by the base language and assigned to variables to which this specification refers as __begin and __end respectively. Both __begin and __end are privatized. For the purpose of the rest of the standard __begin is the iteration variable of the range-for loop.

SVG-Viewer needed.

RestrictionsThe following restrictions also apply:

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

Cross References