1 // RUN: %libomp-compile-and-run
2 // UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7, gcc-8
3 // UNSUPPORTED: icc, clang
10 #define NUM_THREADS_PER_TEAM 3
12 int main(int argc
, char** argv
) {
13 #pragma omp teams num_teams(NUM_TEAMS)
16 int members
[NUM_THREADS_PER_TEAM
];
17 // Only an upper bound is guaranteed for number of teams
18 int nteams
= omp_get_num_teams();
19 if (nteams
> NUM_TEAMS
) {
20 fprintf(stderr
, "error: too many teams: %d\n", nteams
);
23 for (i
= 0; i
< NUM_THREADS_PER_TEAM
; ++i
)
25 #pragma omp parallel num_threads(NUM_THREADS_PER_TEAM) private(i)
27 int tid
= omp_get_thread_num();
28 int team_id
= omp_get_team_num();
29 int nthreads
= omp_get_num_threads();
30 if (nthreads
!= NUM_THREADS_PER_TEAM
) {
31 fprintf(stderr
, "error: detected number of threads (%d) is not %d\n",
32 nthreads
, NUM_THREADS_PER_TEAM
);
35 if (tid
< 0 || tid
>= nthreads
) {
36 fprintf(stderr
, "error: thread id is out of range: %d\n", tid
);
39 if (team_id
< 0 || team_id
> omp_get_num_teams()) {
40 fprintf(stderr
, "error: team id is out of range: %d\n", team_id
);
43 members
[omp_get_thread_num()] = 1;
47 for (i
= 0; i
< NUM_THREADS_PER_TEAM
; ++i
) {
48 if (members
[i
] != 1) {
49 fprintf(stderr
, "error: worker %d not flagged\n", i
);