LLVM OpenMP 20.0.0git
kmp-affinity.c
Go to the documentation of this file.
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
5// REQUIRES: linux
6
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
12
13// Compare place lists. Make sure every place in p1 is in p2.
14static int compare_places(const place_list_t *p1, const place_list_t *p2) {
15 int i, j;
16 for (i = 0; i < p1->num_places; ++i) {
17 int found = 0;
18 for (j = 0; j < p2->num_places; ++j) {
19 if (affinity_mask_equal(p1->masks[i], p2->masks[j])) {
20 found = 1;
21 break;
22 }
23 }
24 if (!found) {
25 printf("Found place in p1 not in p2!\n");
26 printf("p1 places:\n");
28 printf("\n");
29 printf("p2 places:\n");
31 return EXIT_FAILURE;
32 }
33 }
34 return EXIT_SUCCESS;
35}
36
37static int check_places() {
38 int status;
39 const char *value = getenv("KMP_AFFINITY");
40 if (!value) {
41 fprintf(stderr, "error: must set OMP_PLACES envirable for this test!\n");
42 return EXIT_FAILURE;
43 }
44 place_list_t *places, *openmp_places;
45 if (strstr(value, "socket")) {
47 } else if (strstr(value, "core")) {
49 } else if (strstr(value, "thread")) {
51 } else {
52 fprintf(
53 stderr,
54 "error: KMP_AFFINITY granularity must be one of thread,core,socket!\n");
55 return EXIT_FAILURE;
56 }
57 openmp_places = topology_alloc_openmp_places();
58 status = compare_places(openmp_places, places);
60 topology_free_places(openmp_places);
61 return status;
62}
63
64int main() {
66 printf("Thread does not have access to all logical processors. Skipping "
67 "test.\n");
68 return EXIT_SUCCESS;
69 }
70 return check_places();
71}
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 int compare_places(const place_list_t *p1, const place_list_t *p2)
Definition: kmp-affinity.c:14
static int check_places()
Definition: kmp-affinity.c:37
int main()
Definition: kmp-affinity.c:64
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)
affinity_mask_t ** masks