Debian Codegraph @

libgomp/testsuite/libgomp.c-c++-common/imperfect3.c

raw
1 /* { dg-do run } */
2
3 /* Like imperfect2.c, but includes bindings in the blocks. */
4
5 static int f1count[3], f2count[3];
6 static int g1count[3], g2count[3];
7
8 #ifndef __cplusplus
9 extern void abort (void);
10 #else
11 extern "C" void abort (void);
12 #endif
13
14 int f1 (int depth, int iter)
15 {
16 f1count[depth]++;
17 return iter;
18 }
19
20 int f2 (int depth, int iter)
21 {
22 f2count[depth]++;
23 return iter;
24 }
25
26 int g1 (int depth, int iter)
27 {
28 g1count[depth]++;
29 return iter;
30 }
31
32 int g2 (int depth, int iter)
33 {
34 g2count[depth]++;
35 return iter;
36 }
37
38 void s1 (int a1, int a2, int a3)
39 {
40 int i, j, k;
41
42 #pragma omp for collapse(3)
43 for (i = 0; i < a1; i++)
44 {
45 int local0 = 0;
46 f1 (local0, i);
47 {
48 g1 (local0, i);
49 for (j = 0; j < a2; j++)
50 {
51 int local1 = 1;
52 f1 (local1, j);
53 {
54 g1 (local1, j);
55 for (k = 0; k < a3; k++)
56 {
57 int local2 = 2;
58 f1 (local2, k);
59 {
60 g1 (local2, k);
61 g2 (local2, k);
62 }
63 f2 (local2, k);
64 }
65 g2 (local1, j);
66 }
67 f2 (local1, j);
68 }
69 g2 (local0, i);
70 }
71 f2 (local0, i);
72 }
73 }
74
75 int
76 main (void)
77 {
78 f1count[0] = 0;
79 f1count[1] = 0;
80 f1count[2] = 0;
81 f2count[0] = 0;
82 f2count[1] = 0;
83 f2count[2] = 0;
84
85 g1count[0] = 0;
86 g1count[1] = 0;
87 g1count[2] = 0;
88 g2count[0] = 0;
89 g2count[1] = 0;
90 g2count[2] = 0;
91
92 s1 (3, 4, 5);
93
94 /* All intervening code at the same depth must be executed the same
95 number of times. */
96 if (f1count[0] != f2count[0]) abort ();
97 if (f1count[1] != f2count[1]) abort ();
98 if (f1count[2] != f2count[2]) abort ();
99 if (g1count[0] != f1count[0]) abort ();
100 if (g2count[0] != f1count[0]) abort ();
101 if (g1count[1] != f1count[1]) abort ();
102 if (g2count[1] != f1count[1]) abort ();
103 if (g1count[2] != f1count[2]) abort ();
104 if (g2count[2] != f1count[2]) abort ();
105
106 /* Intervening code must be executed at least as many times as the loop
107 that encloses it. */
108 if (f1count[0] < 3) abort ();
109 if (f1count[1] < 3 * 4) abort ();
110
111 /* Intervening code must not be executed more times than the number
112 of logical iterations. */
113 if (f1count[0] > 3 * 4 * 5) abort ();
114 if (f1count[1] > 3 * 4 * 5) abort ();
115
116 /* Check that the innermost loop body is executed exactly the number
117 of logical iterations expected. */
118 if (f1count[2] != 3 * 4 * 5) abort ();
119 }