1 // RUN: %libomp-compile && env OMP_NUM_THREADS=2,2,2,2,2 OMP_THREAD_LIMIT=16 \
4 #include "omp_testsuite.h"
6 // When compiler supports num_threads clause list format and strict modifier,
7 // remove the following and use num_threads clause directly
8 #if defined(__cplusplus)
12 int __kmpc_global_thread_num(void *loc
);
13 void __kmpc_push_num_threads_list(void *loc
, int gtid
, unsigned length
,
15 void __kmpc_push_num_threads_strict(void *loc
, int gtid
, int nth
, int sev
,
17 void __kmpc_push_num_threads_list_strict(void *loc
, int gtid
, unsigned length
,
18 int *list
, int sev
, const char *msg
);
20 #if defined(__cplusplus)
24 int test_omp_parallel_num_threads_strict() {
27 // Test regular runtime warning about exceeding thread limit.
28 // Tolerate whatever value was given.
29 #pragma omp parallel reduction(+ : num_failed) num_threads(22)
31 num_failed
= num_failed
+ !(omp_get_num_threads() <= 22);
33 // Test with 4 threads and strict -- no problem, no warning.
34 __kmpc_push_num_threads_strict(NULL
, __kmpc_global_thread_num(NULL
), 4, 1,
35 "This warning shouldn't happen.");
36 #pragma omp parallel reduction(+ : num_failed) // num_threads(strict:4)
38 num_failed
= num_failed
+ !(omp_get_num_threads() == 4);
40 // Exceed limit, specify user warning message. Tolerate whatever was given.
41 __kmpc_push_num_threads_strict(NULL
, __kmpc_global_thread_num(NULL
), 20, 1,
42 "User-supplied warning for strict.");
43 #pragma omp parallel reduction(+ : num_failed)
44 // num_threads(strict:20) severity(warning)
45 // message("User-supplied warning for strict.")
47 num_failed
= num_failed
+ !(omp_get_num_threads() <= 20);
49 // Exceed limit, no user message, use runtime default message for strict.
50 // Tolerate whatever value was given.
51 __kmpc_push_num_threads_strict(NULL
, __kmpc_global_thread_num(NULL
), 21, 1,
53 #pragma omp parallel reduction(+ : num_failed) // num_threads(strict:21)
55 num_failed
= num_failed
+ !(omp_get_num_threads() <= 21);
57 // Exceed limit at top level. Should see user warning message.
58 int threads3
[2] = {24, 2};
59 __kmpc_push_num_threads_list_strict(NULL
, __kmpc_global_thread_num(NULL
), 2,
61 "User-supplied warning on strict list.");
62 #pragma omp parallel reduction(+ : num_failed)
63 // num_threads(strict:24,2) severity(warning)
64 // message("User-supplied warning on strict. list") // 1st level
67 num_failed
= num_failed
+ !(omp_get_num_threads() <= 24);
68 #pragma omp parallel reduction(+ : num_failed) // 2nd level
71 num_failed
= num_failed
+ !(omp_get_num_threads() <= 2);
75 // No strict limit at top level. Regular runtime limiting applies.
76 __kmpc_push_num_threads_list(NULL
, __kmpc_global_thread_num(NULL
), 2,
78 #pragma omp parallel reduction(+ : num_failed)
79 // num_threads(24,2) // 1st level
82 num_failed
= num_failed
+ !(omp_get_num_threads() <= 24);
83 #pragma omp parallel reduction(+ : num_failed) // 2nd level
86 num_failed
= num_failed
+ !(omp_get_num_threads() <= 2);
97 for (i
= 0; i
< REPETITIONS
; i
++) {
98 if (!test_omp_parallel_num_threads_strict()) {