#pragma omp distribute

Purpose

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

Syntax

Read syntax diagramSkip visual syntax diagram
                              .-+---+------.   
                              | '-,-'      |   
                              V            |   
>>-#--pragma--omp distribute----+--------+-+-------------------><
                                '-clause-'     

Read syntax diagramSkip visual syntax diagram
>>-block-------------------------------------------------------><

Parameters

clause is any of the following clauses:
collapse(n)
Specifies the number of loops that the omp distribute directive applies to. The expression that is represented by n must evaluate to a positive integer value. If no collapse clause is specified, the omp distribute directive applies only to the immediately following loop.
dist_schedule(static[,chunk_size])
  • If dist_schedule is specified:
    • If chunk_size is specified, groups of chunk_size iterations are assigned in a round-robin fashion to each participating team.
    • If no chunk_size is specified, the iteration space is divided into approximately equal-sized chunks, and each chunk is assigned to each team. At most one chunk is assigned to each team.
  • If dist_schedule is not specified, iterations are distributed as if dist_schedule(static) is specified.
firstprivate(list)
Similar to private, except that the private copy is initialized with the value of the original variable. Data variables in list are separated by commas.
lastprivate(list)
Similar to private. In addition, the value of each new list item from the sequentially last iteration of the distribute loop is assigned back to the original list item. Data variables in list are separated by commas.
private(list)
Declares one or more list items to be private to the team in the enclosing team region. For every list item, a local copy is created for each team as if the variable was automatically declared with no initializers. All references to the original list item in the teams region are replaced with references to the private copy. A copy is created per team; hence, the copy is shared among the threads in the team. Data variables in list are separated by commas.

Usage

  • The omp distribute directive takes effect only if you specify both the -qsmp and -qoffload compiler options.
  • You must use the omp distribute directive on loops that are strictly nested within a teams region.
  • There is no implicit barrier at the end of a omp distribute directive.

Example

const int N = 8;
int a[N];

#pragma omp target map(to: N) map(tofrom: a)
#pragma omp teams num_teams(2) thread_limit(N/2)
#pragma omp distribute
for (i=0, i<N, i++)
{
  a[i] = omp_get_team_num();
}
#pragma omp end distribute
#pragma omp end teams
#pragma omp end target

This target region contains a teams region that consists of two teams. The iterations of the closely nested distribute loop are assigned to these two teams, with the master thread of either team executing N/2 iterations.



Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us