HOME
| OPENMP API Specification: Version 5.1 November 2020

2.11.1  Canonical Loop Nest Form

A loop nest has canonical loop nest form if it conforms to loop-nest in the following grammar:



Symbol

Meaning



  

loop-nest
One of the following:

SVG-Viewer needed.

 

 
for (init-expr; test-expr; incr-expr) 
  loop-body  

SVG-Viewer needed.

or

SVG-Viewer needed.

 

 
for (range-decl: range-expr) 
  loop-body  

A range-based for loop is equivalent to a regular for loop using iterators, as defined in the base language. A range-based for loop has no iteration variable.

SVG-Viewer needed.

or

SVG-Viewer needed.

 

 
DO [ label ] var = lb , ub [ , incr ] 
  [intervening-code] 
  loop-body 
  [intervening-code] 
[ label ] END DO  

If the loop-nest is a nonblock-do-construct, it is treated as a block-do-construct for each DO construct.

The value of incr is the increment of the loop. If not specified, its value is assumed to be 1.

SVG-Viewer needed.

or  

 
loop-transformation-construct  

or  

 
generated-canonical-loop  

loop-body
One of the following:  

 
loop-nest  

or

SVG-Viewer needed.

 

 
{ 
  [intervening-code] 
  loop-body 
  [intervening-code] 
}  

SVG-Viewer needed.

or

SVG-Viewer needed.

 

 
BLOCK 
  [intervening-code] 
  loop-body 
  [intervening-code] 
END BLOCK  

SVG-Viewer needed.

or if none of the previous productions match  

 
final-loop-body  

loop-transformation-construct
A loop transformation construct.

generated-canonical-loop
A generated loop from a loop transformation construct that has canonical loop nest form and for which the loop body matches loop-body.

intervening-code
A structured block sequence that does not contain OpenMP directives or calls to the OpenMP runtime API in its corresponding region, referred to as intervening code. If intervening code is present, then a loop at the same depth within the loop nest is not a perfectly nested loop.

SVG-Viewer needed.

It must not contain iteration statements, continue statements or break statements that apply to the enclosing loop.

SVG-Viewer needed.

SVG-Viewer needed.

It must not contain loops, array expressions, CYCLE statements or EXIT statements.

SVG-Viewer needed.

final-loop-body
A structured block that terminates the scope of loops in the loop nest. If the loop nest is associated with a loop-associated directive, loops in this structured block cannot be associated with that directive.

SVG-Viewer needed.

init-expr
One of the following:

  • var = lb
  • integer-type var = lb

SVG-Viewer needed.

  • pointer-type var = lb

SVG-Viewer needed.

SVG-Viewer needed.

  • random-access-iterator-type var = lb

SVG-Viewer needed.

test-expr
One of the following:

  • var relational-op ub
  • ub relational-op var

relational-op
One of the following:

  • <
  • <=
  • >
  • >=
  • !=

incr-expr
One of the following:

  • ++var
  • var++
  • - - var
  • var - -
  • var += incr
  • var - = incr
  • var = var + incr
  • var = incr + var
  • var = var - incr

The value of incr, respectively 1 and -1 for the increment and decrement operators, is the increment of the loop.

SVG-Viewer needed.

var
One of the following:

SVG-Viewer needed.

  • A variable of a signed or unsigned integer type.

SVG-Viewer needed.

SVG-Viewer needed.

  • A variable of a pointer type.

SVG-Viewer needed.

SVG-Viewer needed.

  • A variable of a random access iterator type.

SVG-Viewer needed.

SVG-Viewer needed.

  • A variable of integer type.

SVG-Viewer needed.

var is the iteration variable of the loop. It must not be modified during the execution of intervening-code or loop-body in the loop.

lb, ub
One of the following:

Expressions of a type compatible with the type of var that are loop invariant with respect to the outermost loop.

or

One of the following:

where var-outer is of a type compatible with the type of var.

or

If var is of an integer type, one of the following:

where var-outer is of an integer type.

lb and ub are loop bounds. A loop for which lb or ub refers to var-outer is a non-rectangular loop. If var is of an integer type, var-outer must be of an integer type with the same signedness and bit precision as the type of var.

The coefficient in a loop bound is 0 if the bound does not refer to var-outer. If a loop bound matches a form in which a1 appears, the coefficient is -a1 if the product of var-outer and a1 is subtracted from a2, and otherwise the coefficient is a1. For other matched forms where a1 does not appear, the coefficient is -1 if var-outer is subtracted from a2, and otherwise the coefficient is 1.

a1, a2, incr
Integer expressions that are loop invariant with respect to the outermost loop of the loop nest.

If the loop is associated with a loop-associated directive, the expressions are evaluated before the construct formed from that directive.

var-outer
The loop iteration variable of a surrounding loop in the loop nest.

SVG-Viewer needed.

range-decl
A declaration of a variable as defined by the base language for range-based for loops.

range-expr
An expression that is valid as defined by the base language for range-based for loops. It must be invariant with respect to the outermost loop of the loop nest and the iterator derived from it must be a random access iterator.

SVG-Viewer needed.

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.

A loop-associated directive controls some number of the outermost loops of an associated loop nest, called the associated loops, in accordance with its specified clauses. 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:

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

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.

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 effects within the lb, ub, incr, or range-expr expressions occur is unspecified.

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 defined.

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 unspecified but will be the same for all intervening code at the same depth, at least once per iteration of the loop enclosing 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 unspecified.

Restrictions Restrictions to canonical loop nests are as follows:

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

Cross References