1 // RUN: %libomp-compile-and-run
3 // Linking fails for icc 18/19
4 // UNSUPPORTED: icc-18, icc-19
15 typedef int kmp_int32
;
16 typedef struct ident
{
23 extern int __kmpc_global_thread_num(ident_t
*);
24 extern void __kmpc_push_num_teams_51(ident_t
*, kmp_int32
, kmp_int32
, kmp_int32
,
30 void check_num_teams(int num_teams_lb
, int num_teams_ub
, int thread_limit
) {
34 int gtid
= __kmpc_global_thread_num(NULL
);
35 __kmpc_push_num_teams_51(NULL
, gtid
, num_teams_lb
, num_teams_ub
,
38 #pragma omp teams default(shared)
41 int team_num
= omp_get_team_num();
43 nteams
= omp_get_num_teams();
44 priv_nteams
= omp_get_num_teams();
48 int thread_num
= omp_get_thread_num();
49 int teams_ub
, teams_lb
, thr_limit
;
50 if (team_num
== 0 && thread_num
== 0)
51 nthreads
= omp_get_num_threads();
52 priv_nthreads
= omp_get_num_threads();
54 teams_ub
= (num_teams_ub
? num_teams_ub
: priv_nteams
);
55 teams_lb
= (num_teams_lb
? num_teams_lb
: teams_ub
);
56 thr_limit
= (thread_limit
? thread_limit
: priv_nthreads
);
58 if (priv_nteams
< teams_lb
|| priv_nteams
> teams_ub
) {
59 fprintf(stderr
, "error: invalid number of teams=%d\n", priv_nteams
);
62 if (priv_nthreads
> thr_limit
) {
63 fprintf(stderr
, "error: invalid number of threads=%d\n", priv_nthreads
);
70 if (a
!= nteams
* nthreads
) {
71 fprintf(stderr
, "error: a (%d) != nteams * nthreads (%d)\n", a
,
75 printf("#teams %d, #threads %d: Hello!\n", nteams
, nthreads
);
79 int main(int argc
, char *argv
[]) {
80 omp_set_num_threads(NT
);
82 check_num_teams(1, 8, 2);
83 check_num_teams(2, 2, 2);
84 check_num_teams(2, 2, 0);
85 check_num_teams(8, 16, 2);
86 check_num_teams(9, 16, 0);
87 check_num_teams(9, 16, 2);
88 check_num_teams(2, 3, 0);
89 check_num_teams(0, 0, 2);
90 check_num_teams(0, 4, 0);
91 check_num_teams(0, 2, 2);
93 printf("Test Passed\n");