Intel® C++ Compiler 16.0 User and Reference Guide
Creates a league of thread teams to execute the structured block in the master thread of each team.
#pragma omp teams [clause, clause, ...] |
structured-block
clause |
Can be zero or more of the following clauses:
|
The thread that encounters this pragma constructs a league of thread teams that execute the structured-block in the master thread of each team. The num_teams ( integer expression ) clause specifies the number of teams to create, and the thread_limit ( integer expression ) clause specifies the maximum number of threads participating in the contention group that each team initiates. In each case, the integer expression must evaluate to a positive integer value. At most one thread_limit clause can be used with this pragma. If num_teams is not specified, the default is one.
Each team has a unique team number that can be obtained by calling the OpenMP* library routine omp_get_team_num() which will return a value in the range of zero to the number of teams minus 1.
Within the teams each thread has a unique thread identifier returned by the OpenMP* library function omp_get_thread_num(). As in any thread team, the thread identifier starts at zero for the master thread up to the number of threads minus one for the remaining threads.
Immediately after this pragma, only the master threads in each team are executing, the other team members will only start to execute at the next (nested) parallel region. Therefore there are only num_teams threads executing, and each of them has omp_get_thread_num() == 0.
The number of teams created remains constant for the duration of this pragma.
The structured block must remain within the pragma and not depend on the order of the clauses in the pragma.
The structured block can contain the following constructs:
distribute
parallel
parallel sections
parallel workshare
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]; } } } } } |