1 // RUN: %libomp-compile -D_GNU_SOURCE
2 // RUN: env OMP_PLACES=threads %libomp-run
3 // RUN: env OMP_PLACES=cores %libomp-run
4 // RUN: env OMP_PLACES=sockets %libomp-run
10 #include "libomp_test_affinity.h"
11 #include "libomp_test_topology.h"
13 // Compare place lists. The order is not taken into consideration here.
14 // The OS detection might have the cores/sockets in a different
15 // order from the runtime.
16 static int compare_places(const place_list_t
*p1
, const place_list_t
*p2
) {
18 if (p1
->num_places
!= p2
->num_places
) {
19 fprintf(stderr
, "error: places do not have same number of places! (p1 has "
21 p1
->num_places
, p2
->num_places
);
22 printf("p1 places:\n");
23 topology_print_places(p1
);
25 printf("p2 places:\n");
26 topology_print_places(p2
);
29 for (i
= 0; i
< p1
->num_places
; ++i
) {
31 for (j
= 0; j
< p2
->num_places
; ++j
) {
32 if (affinity_mask_equal(p1
->masks
[i
], p2
->masks
[j
])) {
38 printf("Found difference in places!\n");
39 printf("p1 places:\n");
40 topology_print_places(p1
);
42 printf("p2 places:\n");
43 topology_print_places(p2
);
50 static int check_places() {
52 const char *value
= getenv("OMP_PLACES");
54 fprintf(stderr
, "error: must set OMP_PLACES envirable for this test!\n");
57 place_list_t
*places
, *openmp_places
;
58 if (strcmp(value
, "sockets") == 0) {
59 places
= topology_alloc_type_places(TOPOLOGY_OBJ_SOCKET
);
60 } else if (strcmp(value
, "cores") == 0) {
61 places
= topology_alloc_type_places(TOPOLOGY_OBJ_CORE
);
62 } else if (strcmp(value
, "threads") == 0) {
63 places
= topology_alloc_type_places(TOPOLOGY_OBJ_THREAD
);
66 "error: OMP_PLACES must be one of threads,cores,sockets!\n");
69 openmp_places
= topology_alloc_openmp_places();
70 status
= compare_places(places
, openmp_places
);
71 topology_free_places(places
);
72 topology_free_places(openmp_places
);
77 if (!topology_using_full_mask()) {
78 printf("Thread does not have access to all logical processors. Skipping "
82 return check_places();