1#ifndef LIBOMP_TEST_TOPOLOGY_H
2#define LIBOMP_TEST_TOPOLOGY_H
33 }
while (c != EOF && (isspace(c) || c ==
'\n' || c ==
'\r'));
43 n = fscanf(
f,
"%d", number);
54 FILE *
f = fopen(filename,
"r");
61 int c,
i, n, lower, upper;
67 fprintf(stderr,
"syntax error: expected integer\n");
74 if (c == EOF || c ==
',') {
78 }
else if (c ==
'-') {
80 if (n == EOF || n == 0) {
81 fprintf(stderr,
"syntax error: expected integer\n");
85 for (
i = lower;
i <= upper; ++
i)
90 }
else if (c ==
',') {
93 fprintf(stderr,
"syntax error: unexpected character: '%c (%d)'\n", c,
99 fprintf(stderr,
"syntax error: unexpected character: '%c (%d)'\n", c, c);
105 if (
status == EXIT_FAILURE) {
117 snprintf(
buf,
sizeof(
buf),
"/sys/devices/system/cpu/cpu%d", cpu);
118 DIR *dir = opendir(
buf);
138 for (cpu = 0; cpu < num_cpus; ++cpu) {
152 int i, cpu, num_places, num_unique;
159 for (cpu = 0; cpu < num_cpus; ++cpu) {
162 snprintf(
buf,
sizeof(
buf),
163 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list",
167 snprintf(
buf,
sizeof(
buf),
168 "/sys/devices/system/cpu/cpu%d/topology/core_siblings_list",
175 fprintf(stderr,
"Unknown topology type (%d)\n", (
int)
type);
180 for (
i = 0;
i < num_unique; ++
i) {
189 masks[num_unique++] =
mask;
191 place_nums = (
int *)malloc(
sizeof(
int) * num_unique);
192 for (
i = 0;
i < num_unique; ++
i)
195 places->
masks = masks;
203 int num_places = omp_get_num_places();
207 int *place_nums = (
int *)malloc(
sizeof(
int) * num_places);
208 for (place = 0; place < num_places; ++place) {
209 int num_procs = omp_get_place_num_procs(place);
210 int *ids = (
int *)malloc(
sizeof(
int) * num_procs);
211 omp_get_place_proc_ids(place, ids);
213 for (
i = 0;
i < num_procs; ++
i)
216 place_nums[place] = place;
220 places->
masks = masks;
227 int num_places = omp_get_partition_num_places();
229 int *place_nums = (
int *)malloc(
sizeof(
int) * num_places);
232 omp_get_partition_place_nums(place_nums);
233 for (
p = 0;
p < num_places; ++
p) {
234 int place = place_nums[
p];
235 int num_procs = omp_get_place_num_procs(place);
236 int *ids = (
int *)malloc(
sizeof(
int) * num_procs);
237 if (num_procs == 0) {
238 fprintf(stderr,
"place %d has 0 procs?\n", place);
241 omp_get_place_proc_ids(place, ids);
243 for (
i = 0;
i < num_procs; ++
i)
246 fprintf(stderr,
"place %d has 0 procs set?\n", place);
253 places->
masks = masks;
272 for (
i = 0;
i <
p->num_places; ++
i) {
274 printf(
"Place %d: %s\n",
p->place_nums[
i],
buf);
281 const char *format, ...) {
283 va_start(
args, format);
286 case omp_proc_bind_false:
289 case omp_proc_bind_true:
292 case omp_proc_bind_master:
293 pb =
"Master (Primary)";
295 case omp_proc_bind_close:
298 case omp_proc_bind_spread:
302 pb =
"(Unknown Proc Bind Type)";
305 if (proc_bind == omp_proc_bind_spread || proc_bind == omp_proc_bind_close) {
307 fprintf(stderr,
"%s : (T(%d) <= P(%d)) : ", pb, T, P);
309 fprintf(stderr,
"%s : (T(%d) > P(%d)) : ", pb, T, P);
312 fprintf(stderr,
"%s : T = %d, P = %d : ", pb, T, P);
314 vfprintf(stderr, format,
args);
325 int T,
i,
j, place, low, high, first, last,
count, current_place, num_places;
326 const int *place_nums;
327 int P =
parent->num_places;
333 for (
i = 0;
i < nchildren; ++
i)
335 partitions[T++] = children[
i];
337 if (proc_bind != omp_proc_bind_spread && proc_bind != omp_proc_bind_close &&
338 proc_bind != omp_proc_bind_master)
340 "Cannot check this proc bind type\n");
342 if (proc_bind == omp_proc_bind_spread) {
345 for (
i = 0;
i < T; ++
i) {
346 partition = partitions[
i];
352 high = P / T + (P % T ? 1 : 0);
353 if (num_places != low && num_places != high) {
355 "Incorrect number of places for thread %d: %d. "
356 "Expecting between %d and %d\n",
357 i, num_places, low, high);
360 for (
j = 1;
j < num_places; ++
j) {
361 if (place_nums[
j] != (place_nums[
j - 1] + 1) % P) {
363 "Not consecutive places: %d, %d in partition\n",
364 place_nums[
j - 1], place_nums[
j]);
367 first = place_nums[0];
368 last = place_nums[num_places - 1];
371 if (current_place !=
parent->current_place) {
374 "Primary thread not on same place (%d) as parent thread (%d)\n",
375 current_place,
parent->current_place);
379 if (current_place != first) {
381 "Thread's current place (%d) is not the first place "
382 "in its partition [%d, %d]\n",
383 current_place, first, last);
389 for (
j = 0;
j <
i; ++
j) {
392 if (f1 > l1 && f2 > l2) {
394 "partitions intersect. [%d, %d] and [%d, %d]\n", f1,
397 if (f1 > l1 && f2 <= l2)
398 if (f1 < l2 || l1 > f2) {
400 "partitions intersect. [%d, %d] and [%d, %d]\n", f1,
403 if (f1 <= l1 && f2 > l2)
404 if (f2 < l1 || l2 > f1) {
406 "partitions intersect. [%d, %d] and [%d, %d]\n", f1,
409 if (f1 <= l1 && f2 <= l2)
410 if (!(f2 > l1 || l2 < f1)) {
412 "partitions intersect. [%d, %d] and [%d, %d]\n", f1,
420 for (
i = 0;
i < T; ++
i) {
421 if (partitions[
i]->num_places != 1) {
424 "Incorrect number of places for thread %d: %d. Expecting 1\n",
i,
425 partitions[
i]->num_places);
430 high = T / P + (T % P ? 1 : 0);
431 for (
i = 1,
count = 1;
i < T; ++
i) {
432 if (partitions[
i]->place_nums[0] == partitions[
i - 1]->place_nums[0]) {
437 "Too many threads have place %d for their partition\n",
438 partitions[
i]->place_nums[0]);
444 "Not enough threads have place %d for their partition\n",
445 partitions[
i]->place_nums[0]);
452 if (
parent->current_place != -1 &&
453 current_place !=
parent->current_place) {
456 "Primary thread not on same place (%d) as parent thread (%d)\n",
457 current_place,
parent->current_place);
460 }
else if (proc_bind == omp_proc_bind_close ||
461 proc_bind == omp_proc_bind_master) {
463 for (
i = 0;
i < T; ++
i) {
464 partition = partitions[
i];
468 if (
parent->num_places != num_places) {
470 "Number of places in subpartition (%d) does not match "
472 num_places,
parent->num_places);
474 for (
j = 0;
j < num_places; ++
j) {
475 if (
parent->place_nums[
j] != place_nums[
j]) {
477 "Subpartition place (%d) does not match "
478 "parent partition place (%d)\n",
479 place_nums[
j],
parent->place_nums[
j]);
487 if (proc_bind == omp_proc_bind_close) {
491 for (
i = 0;
i < T; ++
i) {
492 partition = partitions[
i];
494 if (current_place !=
parent->place_nums[
j]) {
497 "Thread %d's current place (%d) is incorrect. expected %d\n",
i,
498 current_place,
parent->place_nums[
j]);
506 high = T / P + (T % P ? 1 : 0);
508 if (partitions[0]->current_place !=
parent->current_place) {
511 "Primary thread's place (%d) is not parent thread's place (%d)\n",
512 partitions[0]->current_place,
parent->current_place);
514 for (
i = 1;
i < T; ++
i) {
516 if (current_place ==
parent->place_nums[
j]) {
521 "Too many threads have place %d for their current place\n",
528 "Not enough threads have place %d for their current place\n",
532 if (current_place !=
parent->place_nums[
j]) {
535 "Thread %d's place (%d) is not corret. Expected %d\n",
i,
536 partitions[
i]->current_place,
parent->place_nums[
j]);
545 for (
i = 0;
i < T; ++
i) {
546 if (partitions[
i]->current_place !=
parent->current_place) {
549 "Thread %d's place (%d) is not the primary thread's place (%d)\n",
550 i, partitions[
i]->current_place,
parent->current_place);
557 for (
i = 0;
i < T; ++
i) {
562 for (
j = 0;
j < num_places; ++
j)
563 if (partitions[
i]->place_nums[
j] == current_place)
565 if (
j == num_places) {
567 "Thread %d's current place (%d) is not within its "
568 "partition [%d, %d]\n",
569 i, current_place, first, last);
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 mask
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 parent
void const char const char int ITT_FORMAT __itt_group_sync p
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 volatile kmp_i18n_cat_status_t status
static int affinity_mask_isset(const affinity_mask_t *mask, int cpu)
static affinity_mask_t * affinity_mask_alloc()
static int affinity_mask_count(const affinity_mask_t *mask)
static int affinity_mask_equal(const affinity_mask_t *mask1, const affinity_mask_t *mask2)
static void affinity_mask_free(affinity_mask_t *mask)
static void affinity_mask_set(affinity_mask_t *mask, int cpu)
static size_t affinity_mask_snprintf(char *buf, size_t bufsize, const affinity_mask_t *mask)
static void get_thread_affinity(affinity_mask_t *mask)
static void topology_print_places(const place_list_t *p)
static place_list_t * topology_alloc_openmp_places()
static place_list_t * topology_alloc_openmp_partition()
static place_list_t * topology_alloc_type_places(topology_obj_type_t type)
static void proc_bind_check(omp_proc_bind_t proc_bind, const place_list_t *parent, place_list_t **children, int nchildren)
static int topology_using_full_mask()
static void topology_free_places(place_list_t *places)
static int topology_get_num_cpus()
static void proc_bind_die(omp_proc_bind_t proc_bind, int T, int P, const char *format,...)
static affinity_mask_t * topology_get_mask_from_file(const char *filename)
static int get_first_nonspace_from_file(FILE *f)
static int get_integer_from_file(FILE *f, int *number)