1 // RUN: %libomp-compile-and-run
11 #define streqls(s1, s2) (!strcmp(s1, s2))
13 #define check(condition) \
15 fprintf(stderr, "error: %s: %d: " STR(condition) "\n", __FILE__, \
20 #define BUFFER_SIZE 1024
22 char buf
[BUFFER_SIZE
];
23 #pragma omp threadprivate(buf)
25 char* get_string(size_t check_needed
) {
26 size_t needed
= omp_capture_affinity(buf
, BUFFER_SIZE
, NULL
);
27 //printf("buf = %s\n", buf);
28 check(needed
< BUFFER_SIZE
);
29 if (check_needed
!= 0) {
30 check(needed
== check_needed
);
35 void check_thread_num_padded_rjustified() {
37 const char* formats
[2] = {"%0.8{thread_num}", "%0.8n"};
38 for (i
= 0; i
< sizeof(formats
)/sizeof(formats
[0]); ++i
) {
39 omp_set_affinity_format(formats
[i
]);
40 #pragma omp parallel num_threads(8)
43 int tid
= omp_get_thread_num();
44 char ctid
= '0' + (char)tid
;
45 char* s
= get_string(8);
46 for (j
= 0; j
< 7; ++j
) {
54 void check_thread_num_rjustified() {
56 const char* formats
[2] = {"%.12{thread_num}", "%.12n"};
57 for (i
= 0; i
< sizeof(formats
)/sizeof(formats
[0]); ++i
) {
58 omp_set_affinity_format(formats
[i
]);
59 #pragma omp parallel num_threads(8)
62 int tid
= omp_get_thread_num();
63 char ctid
= '0' + (char)tid
;
64 char* s
= get_string(12);
65 for (j
= 0; j
< 11; ++j
) {
73 void check_thread_num_ljustified() {
75 const char* formats
[2] = {"%5{thread_num}", "%5n"};
76 for (i
= 0; i
< sizeof(formats
)/sizeof(formats
[0]); ++i
) {
77 omp_set_affinity_format(formats
[i
]);
78 #pragma omp parallel num_threads(8)
81 int tid
= omp_get_thread_num();
82 char ctid
= '0' + (char)tid
;
83 char* s
= get_string(5);
85 for (j
= 1; j
< 5; ++j
) {
92 void check_thread_num_padded_ljustified() {
94 const char* formats
[2] = {"%018{thread_num}", "%018n"};
95 for (i
= 0; i
< sizeof(formats
)/sizeof(formats
[0]); ++i
) {
96 omp_set_affinity_format(formats
[i
]);
97 #pragma omp parallel num_threads(8)
100 int tid
= omp_get_thread_num();
101 char ctid
= '0' + (char)tid
;
102 char* s
= get_string(18);
104 for (j
= 1; j
< 18; ++j
) {
111 int main(int argc
, char** argv
) {
112 check_thread_num_ljustified();
113 check_thread_num_rjustified();
114 check_thread_num_padded_ljustified();
115 check_thread_num_padded_rjustified();