1 // RUN: %libomp-compile -D_GNU_SOURCE
2 // RUN: env KMP_AFFINITY=granularity=thread,compact %libomp-run
3 // RUN: env KMP_AFFINITY=granularity=core,compact %libomp-run
4 // RUN: env KMP_AFFINITY=granularity=socket,compact %libomp-run
10 #include "libomp_test_affinity.h"
11 #include "libomp_test_topology.h"
13 // Compare place lists. Make sure every place in p1 is in p2.
14 static int compare_places(const place_list_t
*p1
, const place_list_t
*p2
) {
16 for (i
= 0; i
< p1
->num_places
; ++i
) {
18 for (j
= 0; j
< p2
->num_places
; ++j
) {
19 if (affinity_mask_equal(p1
->masks
[i
], p2
->masks
[j
])) {
25 printf("Found place in p1 not in p2!\n");
26 printf("p1 places:\n");
27 topology_print_places(p1
);
29 printf("p2 places:\n");
30 topology_print_places(p2
);
37 static int check_places() {
39 const char *value
= getenv("KMP_AFFINITY");
41 fprintf(stderr
, "error: must set OMP_PLACES envirable for this test!\n");
44 place_list_t
*places
, *openmp_places
;
45 if (strstr(value
, "socket")) {
46 places
= topology_alloc_type_places(TOPOLOGY_OBJ_SOCKET
);
47 } else if (strstr(value
, "core")) {
48 places
= topology_alloc_type_places(TOPOLOGY_OBJ_CORE
);
49 } else if (strstr(value
, "thread")) {
50 places
= topology_alloc_type_places(TOPOLOGY_OBJ_THREAD
);
54 "error: KMP_AFFINITY granularity must be one of thread,core,socket!\n");
57 openmp_places
= topology_alloc_openmp_places();
58 status
= compare_places(openmp_places
, places
);
59 topology_free_places(places
);
60 topology_free_places(openmp_places
);
65 if (!topology_using_full_mask()) {
66 printf("Thread does not have access to all logical processors. Skipping "
70 return check_places();