HOME
| OPENMP API Specification: Version 5.0 November 2018

2.9.4  distribute Loop Constructs

2.9.4.1 distribute Construct

SummaryThe distribute construct specifies that the iterations of one or more loops will be executed by the initial teams in the context of their implicit tasks. The iterations are distributed across the initial threads of all initial teams that execute the teams region to which the distribute region binds.

Syntax

SVG-Viewer needed.

The syntax of the distribute construct is as follows:  

 
#pragma omp distribute [clause[ [,] clause] ... ] new-line 
   for-loops  

Where clause is one of the following:  

 
private(list) 
firstprivate(list) 
lastprivate(list) 
collapse(n) 
dist_schedule(kind[, chunk_size]) 
allocate([allocator :]list)  

The distribute directive places restrictions on the structure of all associated for-loops. Specifically, all associated for-loops must have canonical loop form (see Section 2.9.1 on page 271).

SVG-Viewer needed.

SVG-Viewer needed.

The syntax of the distribute construct is as follows:  

 
!$omp distribute [clause[ [,] clause] ... ] 
   do-loops 
[!$omp end distribute]  

Where clause is one of the following:  

 
private(list) 
firstprivate(list) 
lastprivate(list) 
collapse(n) 
dist_schedule(kind[, chunk_size]) 
allocate([allocator :]list)  

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

The distribute directive places restrictions on the structure of all associated do-loops. Specifically, all associated do-loops must have canonical loop form (see Section 2.9.1 on page 271).

SVG-Viewer needed.

BindingThe binding thread set for a distribute region is the set of initial threads executing an enclosing teams region. A distribute region binds to this teams region.

DescriptionThe distribute construct is associated with a loop nest consisting of one or more loops that follow the directive. There is no implicit barrier at the end of a distribute construct. To avoid data races the original list items modified due to lastprivate or linear clauses should not be accessed between the end of the distribute construct and the end of the teams region to which the distribute binds.

The collapse clause may be used to specify how many loops are associated with the distribute construct. The parameter of the collapse clause must be a constant positive integer expression. If no collapse clause is present or its parameter is 1, the only loop that is associated with the distribute construct is the one that immediately follows the distribute construct. If a collapse clause is specified with a parameter value greater than 1 and more than one loop is associated with the distribute construct, then the iteration of all associated loops are collapsed into one larger iteration space. The sequential execution of the iterations in all associated loops determines the order of the iterations in the collapsed iteration space.

A distribute loop has logical iterations numbered 0,1,...,N-1 where N is the number of loop iterations, and the logical numbering denotes the sequence in which the iterations would be executed if the set of associated loop(s) were executed sequentially. At the beginning of each logical iteration, the loop iteration variable of each associated loop has the value that it would have if the set of the associated loop(s) were executed sequentially.

If more than one loop is associated with the distribute construct then the number of times that any intervening code between any two associated loops will be executed is unspecified but will be at least once per iteration of the loop enclosing the intervening code and at most once per iteration of the innermost loop associated with the construct. If the iteration count of any loop that is associated with the distribute construct is zero and that loop does not enclose the intervening code, the behavior is unspecified.

The integer type (or kind, for Fortran) used to compute the iteration count for the collapsed loop is implementation defined.

If dist_schedule is specified, kind must be static. If specified, iterations are divided into chunks of size chunk_size, chunks are assigned to the initial teams of the league in a round-robin fashion in the order of the initial team number. When no chunk_size is specified, the iteration space is divided into chunks that are approximately equal in size, and at most one chunk is distributed to each initial team of the league. The size of the chunks is unspecified in this case.

When no dist_schedule clause is specified, the schedule is implementation defined.

Execution Model EventsThe distribute-begin event occurs after an implicit task encounters a distribute construct but before the task starts to execute the structured block of the distribute region. The distribute-end event occurs after an implicit task finishes execution of a distribute region but before it resumes execution of the enclosing context.

Tool CallbacksA thread dispatches a registered ompt_callback_work callback with ompt_scope_begin as its endpoint argument and ompt_work_distribute as its wstype argument for each occurrence of a distribute-begin event in that thread. Similarly, a thread dispatches a registered ompt_callback_work callback with ompt_scope_end as its endpoint argument and ompt_work_distribute as its wstype argument for each occurrence of a distribute-end event in that thread. The callbacks occur in the context of the implicit task. The callbacks have type signature ompt_callback_work_t.

RestrictionsRestrictions to the distribute construct are as follows:

Cross References

2.9.4.2 distribute simd Construct

SummaryThe distribute simd construct specifies a loop that will be distributed across the master threads of the teams region and executed concurrently using SIMD instructions. The distribute simd construct is a composite construct.

Syntax

The syntax of the distribute simd construct is as follows:

SVG-Viewer needed.

 

 
#pragma omp distribute simd [clause[ [,] clause] ... ] newline 
   for-loops  

where clause can be any of the clauses accepted by the distribute or simd directives with identical meanings and restrictions.

SVG-Viewer needed.

SVG-Viewer needed.

 

 
!$omp distribute simd [clause[ [,] clause] ... ] 
   do-loops 
[!$omp end distribute simd]  

where clause can be any of the clauses accepted by the distribute or simd directives with identical meanings and restrictions.

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

SVG-Viewer needed.

DescriptionThe distribute simd construct will first distribute the iterations of the associated loop(s) according to the semantics of the distribute construct and any clauses that apply to the distribute construct. The resulting chunks of iterations will then be converted to a SIMD loop in a manner consistent with any clauses that apply to the simd construct.

Execution Model Events This composite construct generates the same events as the distribute construct.

Tool Callbacks This composite construct dispatches the same callbacks as the distribute construct.

Restrictions

Cross References

2.9.4.3 Distribute Parallel Worksharing-Loop Construct

SummaryThe distribute parallel worksharing-loop construct specifies a loop that can be executed in parallel by multiple threads that are members of multiple teams. The distribute parallel worksharing-loop construct is a composite construct.

Syntax

The syntax of the distribute parallel worksharing-loop construct is as follows:

SVG-Viewer needed.

 

 
#pragma omp distribute parallel for [clause[ [,] clause] ... ] newline 
    for-loops  

where clause can be any of the clauses accepted by the distribute or parallel worksharing-loop directives with identical meanings and restrictions.

SVG-Viewer needed.

SVG-Viewer needed.

 

 
!$omp distribute parallel do [clause[ [,] clause] ... ] 
    do-loops 
[!$omp end distribute parallel do]  

where clause can be any of the clauses accepted by the distribute or parallel worksharing-loop directives with identical meanings and restrictions.

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

SVG-Viewer needed.

DescriptionThe distribute parallel worksharing-loop construct will first distribute the iterations of the associated loop(s) into chunks according to the semantics of the distribute construct and any clauses that apply to the distribute construct. Each of these chunks will form a loop. Each resulting loop will then be distributed across the threads within the teams region to which the distribute construct binds in a manner consistent with any clauses that apply to the parallel worksharing-loop construct.

Execution Model Events This composite construct generates the same events as the distribute and parallel worksharing-loop constructs.

Tool Callbacks This composite construct dispatches the same callbacks as the distribute and parallel worksharing-loop constructs.

Restrictions

Cross References

2.9.4.4 Distribute Parallel Worksharing-Loop SIMD Construct

SummaryThe distribute parallel worksharing-loop SIMD construct specifies a loop that can be executed concurrently using SIMD instructions in parallel by multiple threads that are members of multiple teams. The distribute parallel worksharing-loop SIMD construct is a composite construct.

Syntax

SVG-Viewer needed.

The syntax of the distribute parallel worksharing-loop SIMD construct is as follows:  

 
#pragma omp distribute parallel for simd \ 
            [clause[ [,] clause] ... ] newline 
    for-loops  

where clause can be any of the clauses accepted by the distribute or parallel worksharing-loop SIMD directives with identical meanings and restrictions.

SVG-Viewer needed.

SVG-Viewer needed.

The syntax of the distribute parallel worksharing-loop SIMD construct is as follows:  

 
!$omp distribute parallel do simd [clause[ [,] clause] ... ] 
    do-loops 
[!$omp end distribute parallel do simd]  

where clause can be any of the clauses accepted by the distribute or parallel worksharing-loop SIMD directives with identical meanings and restrictions.

If an end distribute parallel do simd directive is not specified, an end distribute paralleldo simd directive is assumed at the end of the do-loops.

SVG-Viewer needed.

DescriptionThe distribute parallel worksharing-loop SIMD construct will first distribute the iterations of the associated loop(s) according to the semantics of the distribute construct and any clauses that apply to the distribute construct. The resulting loops will then be distributed across the threads contained within the teams region to which the distribute construct binds in a manner consistent with any clauses that apply to the parallel worksharing-loop construct. The resulting chunks of iterations will then be converted to a SIMD loop in a manner consistent with any clauses that apply to the simd construct.

Execution Model Events This composite construct generates the same events as the distribute and parallel worksharing-loop SIMD constructs.

Tool Callbacks This composite construct dispatches the same callbacks as the distribute and parallel worksharing-loop SIMD constructs.

Restrictions

Cross References