| **OPENMP API Specification: "Version 5.2 -- GIT rev 95b2e3a44"**

#### 4.4.2 OpenMP Loop-Iteration Spaces and Vectors

A loop-associated directive controls some number of the outermost loops of an associated loop nest, called
the associated loops, in accordance with its speciﬁed clauses. These associated loops and their loop iteration
variables form an OpenMP loop-iteration space. OpenMP loop-iteration vectors allow other directives to
refer to points in that loop-iteration space.

A loop transformation construct that appears inside a loop nest is replaced according to its semantics before
any loop can be associated with a loop-associated directive that is applied to the loop nest. The depth of the
loop nest is determined according to the loops in the loop nest, after any such replacements have taken
place. A loop counts towards the depth of the loop nest if it is a base language loop statement or generated
loop and it matches loop-nest while applying the production rules for canonical loop nest form to the loop
nest.

The canonical loop nest form allows the iteration count of all associated loops to be computed before
executing the outermost loop.

For any associated loop, the iteration count is computed as follows:

- If
var
has
a
signed
integer
type
and
the
var
operand
of
test-expr
after
usual
arithmetic
conversions
has
an
unsigned
integer
type
then
the
loop
iteration
count
is
computed
from
lb,
test-expr
and
incr
using
an
unsigned
integer
type
corresponding
to
the
type
of
var.
- Otherwise,
if
var
has
an
integer
type
then
the
loop
iteration
count
is
computed
from
lb,
test-expr
and
incr
using
the
type
of
var.

- If
var
has
a
pointer
type
then
the
loop
iteration
count
is
computed
from
lb,
test-expr
and
incr
using
the
type
ptrdiff_t.

- If
var
has
a
random
access
iterator
type
then
the
loop
iteration
count
is
computed
from
lb,
test-expr
and
incr
using
the
type
std::iterator_traits<random-access-iterator-type>::difference_type.
- For
range-based
for
loops,
the
loop
iteration
count
is
computed
from
range-expr
using
the
type
std::iterator_traits<random-access-iterator-type>::difference_type
where
random-access-iterator-type
is
the
iterator
type
derived
from
range-expr.

- The
loop
iteration
count
is
computed
from
lb,
ub
and
incr
using
the
type
of
var.

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

No synchronization is implied during the evaluation of the lb, ub, incr or range-expr expressions. Whether,
in what order, or how many times any side eﬀects within the lb, ub, incr, or range-expr expressions occur is
unspeciﬁed.

Let the number of loops associated with a construct be n. The OpenMP loop-iteration space is the
n-dimensional space deﬁned by the values of var_{i}, 1 ≤ i ≤ n, the iteration variables of the associated
loops, with i = 1 referring to the outermost loop of the loop nest. An OpenMP loop-iteration
vector, which may be used as an argument of OpenMP directives and clauses, then has the
form:

var_{1} [± oﬀset_{1}], var_{2} [± oﬀset_{2}],…, var_{n} [± oﬀset_{n}]

where oﬀset_{i} is a compile-time constant non-negative OpenMP integer expression that facilitates
identiﬁcation of relative points in the loop-iteration space.

The iterations of some number of associated loops can be collapsed into one larger iteration space that is
called the logical iteration space. The particular integer type used to compute the iteration count for the
collapsed loop is implementation deﬁned, but its bit precision must be at least that of the widest type that the
implementation would use for the iteration count of each loop if it was the only associated loop. OpenMP
deﬁnes a special loop-iteration vector, omp_cur_iteration, for which oﬀset_{i} = 0 ∀ i.
This loop-iteration vector enables identiﬁcation of relative points in the logical iteration space
as:

omp_cur_iteration [± logical_oﬀset]

where logical_oﬀset is a compile-time constant non-negative OpenMP integer expression.

For directives that result in the execution of a collapsed logical iteration space, the number of times that any
intervening code between any two loops of the same logical iteration space will be executed is unspeciﬁed
but will be the same for all intervening code at the same depth, at least once per iteration of the
loop that encloses the intervening code and at most once per logical iteration. If the iteration
count of any loop is zero and that loop does not enclose the intervening code, the behavior is
unspeciﬁed.