1 // RUN: %libomp-compile-and-run
2 // RUN: %libomp-run | %python %S/check.py -c 'CHECK' %s
10 #define STR(x) XSTR(x)
12 #define streqls(s1, s2) (!strcmp(s1, s2))
14 #define check(condition) \
16 fprintf(stderr, "error: %s: %d: %s\n", __FILE__, __LINE__, \
22 #define snprintf _snprintf
25 #define BUFFER_SIZE 1024
27 int 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}";
33 length
= strlen(format
);
34 omp_set_affinity_format(format
);
36 needed
= omp_get_affinity_format(buf
, BUFFER_SIZE
);
37 check(streqls(buf
, format
));
38 check(needed
== length
)
40 // Check that it is truncated properly
41 omp_get_affinity_format(buf
, 5);
42 check(streqls(buf
, "tl:%"));
49 size_t needed
, needed2
;
51 tn
= omp_get_thread_num();
52 nt
= omp_get_num_threads();
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
60 omp_capture_affinity(my_buf
, 5, NULL
);
61 check(streqls(my_buf
, supposed
));
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
);
68 // Check that it is truncated properly
70 omp_capture_affinity(my_buf
, 26, second_format
);
71 check(streqls(my_buf
, supposed
));
74 #pragma omp parallel num_threads(4)
76 omp_display_affinity(NULL
);
77 omp_display_affinity(second_format
);
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]+