PR target/77349
[official-gcc.git] / libgomp / testsuite / libgomp.c / affinity-2.c
blobf821657470473004056523fdb1eef41383e8d26c
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" } */
6 #include <omp.h>
7 #include <stdlib.h>
8 #include <stdio.h>
10 int *
11 get_buf (int nump)
13 static int *buf;
14 static size_t buf_size;
15 if ((size_t) nump > buf_size)
17 buf_size *= 2;
18 if (nump > buf_size)
19 buf_size = nump + 64;
20 int *bufn = realloc (buf, buf_size * sizeof (int));
21 if (bufn == NULL)
23 fprintf (stderr, "memory allocation error\n");
24 exit (1);
26 buf = bufn;
28 return buf;
31 void
32 print_place (int count, int *ids)
34 int i, j;
35 printf ("{");
36 for (i = 0; i < count; i++)
38 for (j = i + 1; j < count; j++)
39 if (ids[j] != ids[i] + (j - i))
40 break;
41 if (i)
42 printf (",");
43 if (j == i + 1)
44 printf ("%d", ids[i]);
45 else
47 printf ("%d:%d", ids[i], j - i);
48 i = j - 1;
51 printf ("}\n");
54 void
55 print_place_var (void)
57 int place = omp_get_place_num ();
58 int num_places = omp_get_partition_num_places ();
59 int *ids = get_buf (num_places);
60 omp_get_partition_place_nums (ids);
61 printf ("place %d\n", place);
62 if (num_places)
63 printf ("partition %d-%d\n", ids[0], ids[num_places - 1]);
66 int
67 main ()
69 int i, num = omp_get_num_places (), nump, *ids;
70 printf ("omp_get_num_places () == %d\n", num);
71 for (i = 0; i < num; i++)
73 printf ("place %d ", i);
74 nump = omp_get_place_num_procs (i);
75 ids = get_buf (nump);
76 omp_get_place_proc_ids (i, ids);
77 print_place (nump, ids);
79 print_place_var ();
80 omp_set_nested (1);
81 #pragma omp parallel
82 if (omp_get_thread_num () == omp_get_num_threads () - 1)
84 #pragma omp parallel
85 if (omp_get_thread_num () == omp_get_num_threads () - 1)
86 print_place_var ();
88 return 0;