HOME
| OPENMP API Specification: Version 5.1 November 2020

2.11.7  loop Construct

Summary A loop construct specifies that the logical iterations of the associated loops may execute concurrently and permits the encountering threads to execute the loop accordingly.

Syntax

SVG-Viewer needed.

The syntax of the loop construct is as follows:  

 
#pragma omp loop [clause[ [,] clause] ... ] new-line 
    loop-nest  

where loop-nest is a canonical loop nest and clause is one of the following:  

 
bind(binding) 
collapse(n) 
order([ order-modifier :]concurrent) 
private(list) 
lastprivate(list) 
reduction([default ,]reduction-identifier : list)  

where binding is one of the following:  

 
  teams 
  parallel 
  thread  

SVG-Viewer needed.

SVG-Viewer needed.

The syntax of the loop construct is as follows:

 
!$omp loop [clause[ [,] clause] ... ] 
   loop-nest 
[!$omp end loop]  
where loop-nest is a canonical loop nest and clause is one of the following:
 
bind(binding) 
collapse(n) 
order([ order-modifier :]concurrent) 
private(list) 
lastprivate(list) 
reduction([default ,]reduction-identifier : list)  
where binding is one of the following:
 
  teams 
  parallel 
  thread  

If an end loop directive is not specified, an end loop directive is assumed at the end of the do-loops.

SVG-Viewer needed.

Binding If the bind clause is present on the construct, the binding region is determined by binding. Specifically, if binding is teams and an innermost enclosing teams region exists then the binding region is that teams region; if binding is parallel then the binding region is the innermost enclosing parallel region, which may be an implicit parallel region; and if binding is thread then the binding region is not defined. If the bind clause is not present on the construct and the loop construct is closely nested inside a teams or parallel construct, the binding region is the corresponding teams or parallel region. If none of those conditions hold, the binding region is not defined.

If the binding region is a teams region, then the binding thread set is the set of initial threads that are executing that region. If the binding region is a parallel region, then the binding thread set is the team of threads that are executing that region. If the binding region is not defined, then the binding thread set is the encountering thread.

Description The loop construct is associated with a loop nest that consists of one or more loops that follow the directive. The directive asserts that the iterations may execute in any order, including concurrently.

The collapse clause may be used to specify how many loops are associated with the loop construct. The parameter of the collapse clause must be a constant positive integer expression. If the collapse clause is omitted, the behavior is as if a collapse clause with a parameter value of one was specified. The collapse clause specifies the number of loops that are collapsed into a logical iteration space.

At the beginning of each logical iteration, the loop iteration variable or the variable declared by range-decl of each associated loop has the value that it would have if the set of the associated loops was executed sequentially.

Each logical iteration is executed once per instance of the loop region that is encountered by the binding thread set.

If an order clause is present then the semantics are as described in Section 2.11.3. If the order clause is not present, the behavior is as if an order clause that specifies concurrent appeared on the construct.

The set of threads that may execute the iterations of the loop region is the binding thread set. Each iteration is executed by one thread from this set.

If the loop region binds to a teams region, the threads in the binding thread set may continue execution after the loop region without waiting for all logical iterations of the associated loops to complete. The iterations are guaranteed to complete before the end of the teams region.

If the loop region does not bind to a teams region, all logical iterations of the associated loops must complete before the encountering threads continue execution after the loop region.

For the purpose of determining its consistency with other schedules (see Section 2.11.2), the schedule is defined by the implicit order clause.

The schedule is reproducible if the schedule specified through the implicit order clause is reproducible.

Restrictions Restrictions to the loop construct are as follows:

Cross References