LLVM OpenMP 20.0.0git
omp-places.c
Go to the documentation of this file.
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
5// REQUIRES: linux
6
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
12
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.
16static int compare_places(const place_list_t *p1, const place_list_t *p2) {
17 int i, j;
18 if (p1->num_places != p2->num_places) {
19 fprintf(stderr, "error: places do not have same number of places! (p1 has "
20 "%d, p2 has %d)\n",
21 p1->num_places, p2->num_places);
22 printf("p1 places:\n");
24 printf("\n");
25 printf("p2 places:\n");
27 return EXIT_FAILURE;
28 }
29 for (i = 0; i < p1->num_places; ++i) {
30 int found = 0;
31 for (j = 0; j < p2->num_places; ++j) {
32 if (affinity_mask_equal(p1->masks[i], p2->masks[j])) {
33 found = 1;
34 break;
35 }
36 }
37 if (!found) {
38 printf("Found difference in places!\n");
39 printf("p1 places:\n");
41 printf("\n");
42 printf("p2 places:\n");
44 return EXIT_FAILURE;
45 }
46 }
47 return EXIT_SUCCESS;
48}
49
50static int check_places() {
51 int status;
52 const char *value = getenv("OMP_PLACES");
53 if (!value) {
54 fprintf(stderr, "error: must set OMP_PLACES envirable for this test!\n");
55 return EXIT_FAILURE;
56 }
57 place_list_t *places, *openmp_places;
58 if (strcmp(value, "sockets") == 0) {
60 } else if (strcmp(value, "cores") == 0) {
62 } else if (strcmp(value, "threads") == 0) {
64 } else {
65 fprintf(stderr,
66 "error: OMP_PLACES must be one of threads,cores,sockets!\n");
67 return EXIT_FAILURE;
68 }
69 openmp_places = topology_alloc_openmp_places();
70 status = compare_places(places, openmp_places);
72 topology_free_places(openmp_places);
73 return status;
74}
75
76int main() {
78 printf("Thread does not have access to all logical processors. Skipping "
79 "test.\n");
80 return EXIT_SUCCESS;
81 }
82 return check_places();
83}
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
static volatile kmp_i18n_cat_status_t status
Definition: kmp_i18n.cpp:48
#define i
Definition: kmp_stub.cpp:87
static int affinity_mask_equal(const affinity_mask_t *mask1, const affinity_mask_t *mask2)
static void topology_print_places(const place_list_t *p)
@ TOPOLOGY_OBJ_CORE
@ TOPOLOGY_OBJ_THREAD
@ TOPOLOGY_OBJ_SOCKET
static place_list_t * topology_alloc_openmp_places()
static place_list_t * topology_alloc_type_places(topology_obj_type_t type)
static int topology_using_full_mask()
static void topology_free_places(place_list_t *places)
static int compare_places(const place_list_t *p1, const place_list_t *p2)
Definition: omp-places.c:16
static int check_places()
Definition: omp-places.c:50
int main()
Definition: omp-places.c:76
affinity_mask_t ** masks