Intel® C++ Compiler 16.0 User and Reference Guide
Specifies that the iterations of one of more loops should be shared among the master threads of all thread teams in a league.
#pragma omp distribute [clause, clause, ...] |
for-loop
clause |
Can be zero or more of the following:
|
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]; } } } } } |