Debian Codegraph @

libgomp/testsuite/libgomp.c/affinity-2.c

raw
1 /* { dg-do run } */
2 /* { dg-set-target-env-var OMP_PROC_BIND "spread,close" } */
3 /* { dg-set-target-env-var OMP_PLACES "{6,7}:4:-2,!{2,3}" } */
4 /* { dg-set-target-env-var OMP_NUM_THREADS "2" } */
5 /* { dg-additional-options "-Wno-deprecated-declarations" } */
6
7 #include <omp.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10
11 int *
12 get_buf (int nump)
13 {
14 static int *buf;
15 static size_t buf_size;
16 if ((size_t) nump > buf_size)
17 {
18 buf_size *= 2;
19 if (nump > buf_size)
20 buf_size = nump + 64;
21 int *bufn = realloc (buf, buf_size * sizeof (int));
22 if (bufn == NULL)
23 {
24 fprintf (stderr, "memory allocation error\n");
25 exit (1);
26 }
27 buf = bufn;
28 }
29 return buf;
30 }
31
32 void
33 print_place (int count, int *ids)
34 {
35 int i, j;
36 printf ("{");
37 for (i = 0; i < count; i++)
38 {
39 for (j = i + 1; j < count; j++)
40 if (ids[j] != ids[i] + (j - i))
41 break;
42 if (i)
43 printf (",");
44 if (j == i + 1)
45 printf ("%d", ids[i]);
46 else
47 {
48 printf ("%d:%d", ids[i], j - i);
49 i = j - 1;
50 }
51 }
52 printf ("}\n");
53 }
54
55 void
56 print_place_var (void)
57 {
58 int place = omp_get_place_num ();
59 int num_places = omp_get_partition_num_places ();
60 int *ids = get_buf (num_places);
61 omp_get_partition_place_nums (ids);
62 printf ("place %d\n", place);
63 if (num_places)
64 printf ("partition %d-%d\n", ids[0], ids[num_places - 1]);
65 }
66
67 int
68 main ()
69 {
70 int i, num = omp_get_num_places (), nump, *ids;
71 printf ("omp_get_num_places () == %d\n", num);
72 for (i = 0; i < num; i++)
73 {
74 printf ("place %d ", i);
75 nump = omp_get_place_num_procs (i);
76 ids = get_buf (nump);
77 omp_get_place_proc_ids (i, ids);
78 print_place (nump, ids);
79 }
80 print_place_var ();
81 omp_set_nested (1);
82 #pragma omp parallel
83 if (omp_get_thread_num () == omp_get_num_threads () - 1)
84 {
85 #pragma omp parallel
86 if (omp_get_thread_num () == omp_get_num_threads () - 1)
87 print_place_var ();
88 }
89 return 0;
90 }