LLVM OpenMP 20.0.0git
omp_parallel_num_threads_strict.c
Go to the documentation of this file.
1// RUN: %libomp-compile && env OMP_NUM_THREADS=2,2,2,2,2 OMP_THREAD_LIMIT=16 \
2// RUN: %libomp-run
3#include <stdio.h>
4#include "omp_testsuite.h"
5
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)
9extern "C" {
10#endif
11
13void __kmpc_push_num_threads_list(void *loc, int gtid, unsigned length,
14 int *list);
15void __kmpc_push_num_threads_strict(void *loc, int gtid, int nth, int sev,
16 const char *msg);
17void __kmpc_push_num_threads_list_strict(void *loc, int gtid, unsigned length,
18 int *list, int sev, const char *msg);
19
20#if defined(__cplusplus)
21}
22#endif
23
25 int num_failed = 0;
26
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)
30#pragma omp single
31 num_failed = num_failed + !(omp_get_num_threads() <= 22);
32
33 // Test with 4 threads and strict -- no problem, no warning.
35 "This warning shouldn't happen.");
36#pragma omp parallel reduction(+ : num_failed) // num_threads(strict:4)
37#pragma omp single
38 num_failed = num_failed + !(omp_get_num_threads() == 4);
39
40 // Exceed limit, specify user warning message. Tolerate whatever was given.
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.")
46#pragma omp single
47 num_failed = num_failed + !(omp_get_num_threads() <= 20);
48
49 // Exceed limit, no user message, use runtime default message for strict.
50 // Tolerate whatever value was given.
52 NULL);
53#pragma omp parallel reduction(+ : num_failed) // num_threads(strict:21)
54#pragma omp single
55 num_failed = num_failed + !(omp_get_num_threads() <= 21);
56
57 // Exceed limit at top level. Should see user warning message.
58 int threads3[2] = {24, 2};
60 threads3, 1,
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
65 {
66#pragma omp single
67 num_failed = num_failed + !(omp_get_num_threads() <= 24);
68#pragma omp parallel reduction(+ : num_failed) // 2nd level
69 {
70#pragma omp single
71 num_failed = num_failed + !(omp_get_num_threads() <= 2);
72 }
73 }
74
75 // No strict limit at top level. Regular runtime limiting applies.
77 threads3);
78#pragma omp parallel reduction(+ : num_failed)
79 // num_threads(24,2) // 1st level
80 {
81#pragma omp single
82 num_failed = num_failed + !(omp_get_num_threads() <= 24);
83#pragma omp parallel reduction(+ : num_failed) // 2nd level
84 {
85#pragma omp single
86 num_failed = num_failed + !(omp_get_num_threads() <= 2);
87 }
88 }
89
90 return (!num_failed);
91}
92
93int main() {
94 int i;
95 int num_failed = 0;
96
97 for (i = 0; i < REPETITIONS; i++) {
99 num_failed++;
100 }
101 }
102 return num_failed;
103}
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t length
#define i
Definition: kmp_stub.cpp:87
int test_omp_parallel_num_threads_strict()
void __kmpc_push_num_threads_list(void *loc, int gtid, unsigned length, int *list)
int __kmpc_global_thread_num(void *loc)
void __kmpc_push_num_threads_list_strict(void *loc, int gtid, unsigned length, int *list, int sev, const char *msg)
void __kmpc_push_num_threads_strict(void *loc, int gtid, int nth, int sev, const char *msg)
#define REPETITIONS
Definition: omp_testsuite.h:13
static id loc
int omp_get_num_threads()