| 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: " STR(condition) "\n", __FILE__, \ |
| 17 |
__LINE__); \ |
| 18 |
exit(1); \ |
| 19 |
} |
| 20 |
|
| 21 |
#define BUFFER_SIZE 1024 |
| 22 |
|
| 23 |
int main(int argc, char** argv) { |
| 24 |
char buf[BUFFER_SIZE]; |
| 25 |
size_t needed; |
| 26 |
|
| 27 |
omp_set_affinity_format("0123456789"); |
| 28 |
|
| 29 |
needed = omp_get_affinity_format(buf, BUFFER_SIZE); |
| 30 |
check(streqls(buf, "0123456789")); |
| 31 |
check(needed == 10) |
| 32 |
|
| 33 |
// Check that it is truncated properly |
| 34 |
omp_get_affinity_format(buf, 5); |
| 35 |
check(streqls(buf, "0123")); |
| 36 |
|
| 37 |
#pragma omp parallel |
| 38 |
{ |
| 39 |
char my_buf[512]; |
| 40 |
size_t needed = omp_capture_affinity(my_buf, 512, NULL); |
| 41 |
check(streqls(my_buf, "0123456789")); |
| 42 |
check(needed == 10); |
| 43 |
// Check that it is truncated properly |
| 44 |
omp_capture_affinity(my_buf, 5, NULL); |
| 45 |
check(streqls(my_buf, "0123")); |
| 46 |
} |
| 47 |
|
| 48 |
#pragma omp parallel num_threads(4) |
| 49 |
{ |
| 50 |
omp_display_affinity(NULL); |
| 51 |
} |
| 52 |
|
| 53 |
return 0; |
| 54 |
} |
| 55 |
|
| 56 |
// CHECK: num_threads=4 0123456789 |