Skip gnat.dg/prot7.adb on hppa.
[official-gcc.git] / libgomp / testsuite / libgomp.c-c++-common / taskloop-5.c
blob1b64a6dc4f7e82ef70d76934b5f839796c790e2e
1 /* { dg-do run } */
2 /* { dg-options "-O2" } */
4 int u[64], v, w[64];
6 __attribute__((noinline, noclone)) int
7 test (int a, int b, int c, int d, void (*fn) (int, int, int, int),
8 int *num_tasks, int *min_iters, int *max_iters, int *sep)
10 int i, j, t = 0;
11 __builtin_memset (u, 0, sizeof u);
12 v = 0;
13 fn (a, b, c, d);
14 *min_iters = 0;
15 *max_iters = 0;
16 *num_tasks = v;
17 *sep = v;
18 if (v)
20 *min_iters = u[0];
21 *max_iters = u[0];
22 t = u[0];
23 for (i = 1; i < v; i++)
25 if (*min_iters > u[i])
26 *min_iters = u[i];
27 if (*max_iters < u[i])
28 *max_iters = u[i];
29 t += u[i];
31 if (*min_iters != *max_iters)
33 for (i = 0; i < v - 1; i++)
35 int min_idx = i;
36 for (j = i + 1; j < v; j++)
37 if (w[min_idx] > w[j])
38 min_idx = j;
39 if (min_idx != i)
41 int tem = u[i];
42 u[i] = u[min_idx];
43 u[min_idx] = tem;
44 tem = w[i];
45 w[i] = w[min_idx];
46 w[min_idx] = tem;
49 if (u[0] != *max_iters)
50 __builtin_abort ();
51 for (i = 1; i < v; i++)
52 if (u[i] != u[i - 1])
54 if (*sep != v || u[i] != *min_iters)
55 __builtin_abort ();
56 *sep = i;
60 return t;
63 void
64 grainsize (int a, int b, int c, int d)
66 int i, j = 0, k = 0;
67 #pragma omp taskloop firstprivate (j, k) grainsize(strict:d)
68 for (i = a; i < b; i += c)
70 if (j == 0)
72 #pragma omp atomic capture
73 k = v++;
74 if (k >= 64)
75 __builtin_abort ();
76 w[k] = i;
78 u[k] = ++j;
82 void
83 num_tasks (int a, int b, int c, int d)
85 int i, j = 0, k = 0;
86 #pragma omp taskloop firstprivate (j, k) num_tasks(strict:d)
87 for (i = a; i < b; i += c)
89 if (j == 0)
91 #pragma omp atomic capture
92 k = v++;
93 if (k >= 64)
94 __builtin_abort ();
95 w[k] = i;
97 u[k] = ++j;
102 main ()
104 #pragma omp parallel
105 #pragma omp single
107 int min_iters, max_iters, ntasks, sep;
108 /* If grainsize is present and has strict modifier, # of task loop iters is == grainsize,
109 except that it can be smaller on the last task. */
110 if (test (0, 79, 1, 17, grainsize, &ntasks, &min_iters, &max_iters, &sep) != 79
111 || ntasks != 5 || min_iters != 11 || max_iters != 17 || sep != 4)
112 __builtin_abort ();
113 if (test (-49, 2541, 7, 28, grainsize, &ntasks, &min_iters, &max_iters, &sep) != 370
114 || ntasks != 14 || min_iters != 6 || max_iters != 28 || sep != 13)
115 __builtin_abort ();
116 if (test (7, 21, 2, 15, grainsize, &ntasks, &min_iters, &max_iters, &sep) != 7
117 || ntasks != 1 || min_iters != 7 || max_iters != 7 || sep != 1)
118 __builtin_abort ();
119 /* If num_tasks is present, # of tasks is min (# of loop iters, num_tasks)
120 and each task has at least one iteration. If strict modifier is present,
121 first set of tasks has ceil (# of loop iters / num_tasks) iterations,
122 followed by possibly empty set of tasks with floor (# of loop iters / num_tasks)
123 iterations. */
124 if (test (-51, 2500, 48, 9, num_tasks, &ntasks, &min_iters, &max_iters, &sep) != 54
125 || ntasks != 9 || min_iters != 6 || max_iters != 6 || sep != 9)
126 __builtin_abort ();
127 if (test (0, 57, 1, 9, num_tasks, &ntasks, &min_iters, &max_iters, &sep) != 57
128 || ntasks != 9 || min_iters != 6 || max_iters != 7 || sep != 3)
129 __builtin_abort ();
130 if (test (0, 25, 2, 17, num_tasks, &ntasks, &min_iters, &max_iters, &sep) != 13
131 || ntasks != 13 || min_iters != 1 || max_iters != 1 || sep != 13)
132 __builtin_abort ();
134 return 0;