Debian Codegraph @

libgomp/testsuite/libgomp.c-c++-common/target-imperfect-transform-2.c

raw
1 /* { dg-do run } */
2
3 /* Like imperfect-transform.c, but enables offloading. */
4
5 static int f1count[3], f2count[3];
6 #pragma omp declare target enter (f1count, f2count)
7
8 int
9 f1 (int depth, int iter)
10 {
11 #pragma omp atomic
12 f1count[depth]++;
13 return iter;
14 }
15
16 int
17 f2 (int depth, int iter)
18 {
19 #pragma omp atomic
20 f2count[depth]++;
21 return iter;
22 }
23
24 void
25 s1 (int a1, int a2, int a3)
26 {
27 int i, j, k;
28
29 #pragma omp target parallel for collapse(2) map(always, tofrom:f1count, f2count) private (j, k)
30 for (i = 0; i < a1; i++)
31 {
32 f1 (0, i);
33 for (j = 0; j < a2; j++)
34 {
35 f1 (1, j);
36 #pragma omp tile sizes(5)
37 for (k = 0; k < a3; k++)
38 {
39 f1 (2, k);
40 f2 (2, k);
41 }
42 f2 (1, j);
43 }
44 f2 (0, i);
45 }
46 }
47
48 int
49 main ()
50 {
51 f1count[0] = 0;
52 f1count[1] = 0;
53 f1count[2] = 0;
54 f2count[0] = 0;
55 f2count[1] = 0;
56 f2count[2] = 0;
57
58 s1 (3, 4, 5);
59
60 /* All intervening code at the same depth must be executed the same
61 number of times. */
62 if (f1count[0] != f2count[0]) __builtin_abort ();
63 if (f1count[1] != f2count[1]) __builtin_abort ();
64 if (f1count[2] != f2count[2]) __builtin_abort ();
65
66 /* Intervening code must be executed at least as many times as the loop
67 that encloses it. */
68 if (f1count[0] < 3) __builtin_abort ();
69 if (f1count[1] < 3 * 4) __builtin_abort ();
70
71 /* Intervening code must not be executed more times than the number
72 of logical iterations. */
73 if (f1count[0] > 3 * 4 * 5) __builtin_abort ();
74 if (f1count[1] > 3 * 4 * 5) __builtin_abort ();
75
76 /* Check that the innermost loop body is executed exactly the number
77 of logical iterations expected. */
78 if (f1count[2] != 3 * 4 * 5) __builtin_abort ();
79 }