Debian Codegraph @

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

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