Intel® C++ Compiler 16.0 User and Reference Guide

omp distribute

Specifies that the iterations of one of more loops should be shared among the master threads of all thread teams in a league.

Syntax

#pragma omp distribute [clause, clause, ...]

for-loop

Arguments

clause

Can be zero or more of the following:

collapse ( n )

Specifies how many nested loops of a for loop associated with the OpenMP* for construct should be collapsed into a single loop for running in parallel.

firstprivate( list )

Provides a superset of the functionality provided by the private clause. Each private data object is initialized with the value of the original object.

dist_schedule ( static[, chunk_size] )

private( list )

Declares variables to be private to each thread in a team.

Description

This pragma is associated with a loop nest with one or more closely nested loops inside a teams construct. Multiple loops can be collapsed into a single iteration sequence if a collapse clause is used, as with the omp for pragma and a collapse clause.

Use the collapse clause to specify the number of loops. If you do not specify the collapse clause, then only the loop following the pragma declaration is associated with the pragma.

Example: Multiplying two square matrices by parallelizing two outermost loops

#include <omp.h>
void matmul (float *a, float const *b, float const * c, int N) {
 	#pragma omp teams {
    int i;

    #pragma omp distribute
    for (i=0; i<N; i++) {
      int j;
      #pragma omp parallel for
      for (j=0; j<N; j++) {
        int k;
        for (k=0; k<N; k++) {
          a[i*N+k] = a[i*N+k] + b[i*N+j] * c[j*N+k];
        }
      }
    }
  }
}