LLVM OpenMP 19.0.0git
kmp-abs-hw-subset.c
Go to the documentation of this file.
1// RUN: %libomp-compile -D_GNU_SOURCE
2// RUN: env OMP_PLACES=threads %libomp-run 1 0
3// RUN: env OMP_PLACES=threads %libomp-run 1 1
4// RUN: env OMP_PLACES=threads %libomp-run 2 1
5// RUN: env OMP_PLACES=threads %libomp-run 2 2
6// RUN: env OMP_PLACES=threads %libomp-run 3 1
7// RUN: env OMP_PLACES=threads %libomp-run 3 2
8// REQUIRES: linux
9//
10// The test requires topologies with sockets, cores, threads layers where
11// the socket layer contains multiple threads.
12// The s390x architecture does not produce this topology and seems to have
13// one thread per socket.
14// UNSUPPORTED: s390x-target-arch
15
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
21
22// Check openmp place list to make sure it follow KMP_HW_SUBSET restriction
23static int compare_abs_hw_subset_places(const place_list_t *openmp_places,
24 int nthreads, int offset) {
25 int i, j, expected_per_place;
26 if (openmp_places->num_places != nthreads) {
27 fprintf(
28 stderr,
29 "error: KMP_HW_SUBSET did not restrict the thread resource layer!\n");
30 printf("openmp_places places:\n");
31 topology_print_places(openmp_places);
32 printf("\n");
33 return EXIT_FAILURE;
34 }
35 for (i = 0; i < openmp_places->num_places; ++i) {
36 int count = affinity_mask_count(openmp_places->masks[i]);
37 if (count != 1) {
38 fprintf(stderr, "error: place %d has %d OS procs instead of %d\n", i,
39 count, expected_per_place);
40 return EXIT_FAILURE;
41 }
42 }
43 return EXIT_SUCCESS;
44}
45
46static int check_places(int nthreads, int offset) {
47 char buf[100];
49 const char *value;
50 int status = EXIT_SUCCESS;
51 place_list_t *threads, *openmp_places;
53
54 if (threads->num_places <= 1) {
55 printf("Only one hardware thread to execute on. Skipping test.\n");
56 return status;
57 }
58
59 if (nthreads + offset > threads->num_places) {
60 printf("Only %d total hardware threads to execute on. Skipping test with "
61 "nthreads=%d and offset=%d (too big).\n",
62 threads->num_places, nthreads, offset);
63 return status;
64 }
65
66 value = getenv("OMP_PLACES");
67 if (!value) {
68 fprintf(stderr, "error: OMP_PLACES must be set to threads!\n");
69 return EXIT_FAILURE;
70 }
71
72 snprintf(buf, sizeof(buf), ":1s,%dt@%d", nthreads, offset);
73 setenv("KMP_HW_SUBSET", buf, 1);
74
75 openmp_places = topology_alloc_openmp_places();
76 status = compare_abs_hw_subset_places(openmp_places, nthreads, offset);
77 topology_free_places(threads);
78 topology_free_places(openmp_places);
79 return status;
80}
81
82int main(int argc, char **argv) {
83 int offset = 0;
84 int nthreads = 1;
85
87 printf("Thread does not have access to all logical processors. Skipping "
88 "test.\n");
89 return EXIT_SUCCESS;
90 }
91
92 if (argc != 3) {
93 fprintf(stderr, "usage: %s <nthreads> <offset>\n", argv[0]);
94 return EXIT_FAILURE;
95 }
96
97 nthreads = atoi(argv[1]);
98 offset = atoi(argv[2]);
99
100 return check_places(nthreads, offset);
101}
char buf[BUFFER_SIZE]
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 count
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
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 ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type
static int compare_abs_hw_subset_places(const place_list_t *openmp_places, int nthreads, int offset)
static int check_places()
Definition: kmp-affinity.c:37
static volatile kmp_i18n_cat_status_t status
Definition: kmp_i18n.cpp:48
#define i
Definition: kmp_stub.cpp:87
static int affinity_mask_count(const affinity_mask_t *mask)
static void topology_print_places(const place_list_t *p)
topology_obj_type_t
@ TOPOLOGY_OBJ_THREAD
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
int main()
Definition: test-touch.c:21