1 // RUN: %libomp-compile && env OMP_THREAD_LIMIT=4 %libomp-run 4
2 // RUN: %libomp-compile && env OMP_THREAD_LIMIT=7 %libomp-run 7
4 // OMP_THREAD_LIMIT=N should imply that no more than N threads are active in
9 #include "omp_testsuite.h"
14 fprintf(stderr
, "usage: omp_thread_limit <n>\n");
17 void verify(const char* file_name
, int line_number
, int team_size
) {
18 int num_threads
= omp_get_num_threads();
19 if (team_size
!= num_threads
) {
20 #pragma omp critical(A)
23 snprintf(label
, sizeof(label
), "%s:%d", file_name
, line_number
);
25 printf("failed: %s: team_size(%d) != omp_get_num_threads(%d)\n",
26 label
, team_size
, num_threads
);
31 int main(int argc
, char** argv
)
39 cl_thread_limit
= atoi(argv
[1]);
42 if (omp_get_thread_limit() != cl_thread_limit
) {
43 fprintf(stderr
, "omp_get_thread_limit failed with %d, should be%d\n",
44 omp_get_thread_limit(), cl_thread_limit
);
47 else if (omp_get_max_threads() > cl_thread_limit
) {
49 int team_size
= cl_thread_limit
;
53 omp_set_num_threads(19);
54 verify(__FILE__
, __LINE__
, 1);
57 verify(__FILE__
, __LINE__
, team_size
);
58 verify(__FILE__
, __LINE__
, team_size
);
60 verify(__FILE__
, __LINE__
, 1);
63 #pragma omp parallel num_threads(3)
65 verify(__FILE__
, __LINE__
, 3);
67 #pragma omp parallel num_threads(21)
69 verify(__FILE__
, __LINE__
, team_size
-2);
70 verify(__FILE__
, __LINE__
, team_size
-2);
73 verify(__FILE__
, __LINE__
, 1);
77 fprintf(stderr
, "This test is not applicable for max num_threads='%d'\n",
78 omp_get_max_threads());