LLVM OpenMP 19.0.0git
api2.c
Go to the documentation of this file.
1// RUN: %libomp-compile-and-run
2// RUN: %libomp-run | %python %S/check.py -c 'CHECK' %s
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include <omp.h>
8
9#define XSTR(x) #x
10#define STR(x) XSTR(x)
11
12#define streqls(s1, s2) (!strcmp(s1, s2))
13
14#define check(condition) \
15 if (!(condition)) { \
16 fprintf(stderr, "error: %s: %d: %s\n", __FILE__, __LINE__, \
17 STR(condition)); \
18 exit(1); \
19 }
20
21#if defined(_WIN32)
22#define snprintf _snprintf
23#endif
24
25#define BUFFER_SIZE 1024
26
27int main(int argc, char** argv) {
28 char buf[BUFFER_SIZE];
29 size_t needed, length;
30 const char* format = "tl:%L tn:%n nt:%N an:%a";
31 const char* second_format = "nesting_level:%{nesting_level} thread_num:%{thread_num} num_threads:%{num_threads} ancestor_tnum:%{ancestor_tnum}";
32
33 length = strlen(format);
35
37 check(streqls(buf, format));
38 check(needed == length)
39
40 // Check that it is truncated properly
42 check(streqls(buf, "tl:%"));
43
44 #pragma omp parallel
45 {
46 char my_buf[512];
47 char supposed[512];
48 int tl, tn, nt, an;
49 size_t needed, needed2;
50 tl = omp_get_level();
51 tn = omp_get_thread_num();
53 an = omp_get_ancestor_thread_num(omp_get_level()-1);
54 needed = omp_capture_affinity(my_buf, 512, NULL);
55 needed2 = (size_t)snprintf(supposed, 512, "tl:%d tn:%d nt:%d an:%d", tl, tn, nt, an);
56 check(streqls(my_buf, supposed));
57 check(needed == needed2);
58 // Check that it is truncated properly
59 supposed[4] = '\0';
60 omp_capture_affinity(my_buf, 5, NULL);
61 check(streqls(my_buf, supposed));
62
63 needed = omp_capture_affinity(my_buf, 512, second_format);
64 needed2 = (size_t)snprintf(supposed, 512, "nesting_level:%d thread_num:%d num_threads:%d ancestor_tnum:%d", tl, tn, nt, an);
65 check(streqls(my_buf, supposed));
66 check(needed == needed2);
67
68 // Check that it is truncated properly
69 supposed[25] = '\0';
70 omp_capture_affinity(my_buf, 26, second_format);
71 check(streqls(my_buf, supposed));
72 }
73
74 #pragma omp parallel num_threads(4)
75 {
77 omp_display_affinity(second_format);
78 }
79
80 return 0;
81}
82
83// CHECK: num_threads=4 tl:[0-9]+ tn:[0-9]+ nt:[0-9]+ an:[0-9]+
84// CHECK: num_threads=4 nesting_level:[0-9]+ thread_num:[0-9]+ num_threads:[0-9]+ ancestor_tnum:[0-9]+
char buf[BUFFER_SIZE]
#define BUFFER_SIZE
Definition: api2.c:25
#define streqls(s1, s2)
Definition: api2.c:12
#define check(condition)
Definition: api2.c:14
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 omp_get_affinity_format
Definition: kmp_stub.cpp:38
#define omp_get_ancestor_thread_num
Definition: kmp_stub.cpp:31
#define omp_set_affinity_format
Definition: kmp_stub.cpp:37
#define omp_display_affinity
Definition: kmp_stub.cpp:39
#define omp_capture_affinity
Definition: kmp_stub.cpp:40
int omp_get_num_threads()
int main()
Definition: test-touch.c:21