User and Reference Guide for the Intel® C++ Compiler 14.0
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 num_threads ( integer expression ) clause specifies the greatest number of threads within each team to create. Only one num_threads clause can be used with this pragma. If num_teams is not specified, the default is one. If num_threads is not specified, the default is the number of available hardware threads divided by the number of teams.
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 loop
parallel loop simd
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];
}
}
}
}
} |