Debian Codegraph @

libgomp/testsuite/libgomp.c++/attrs-imperfect1.C

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