Debian Codegraph @

libgomp/testsuite/libgomp.c++/task-reduction-16.C

raw
1 extern "C" void abort ();
2
3 struct S { S (); S (long long int, int); ~S (); static int cnt1, cnt2, cnt3; long long int s; int t; };
4
5 int S::cnt1;
6 int S::cnt2;
7 int S::cnt3;
8
9 S::S ()
10 {
11 #pragma omp atomic
12 cnt1++;
13 }
14
15 S::S (long long int x, int y) : s (x), t (y)
16 {
17 #pragma omp atomic update
18 ++cnt2;
19 }
20
21 S::~S ()
22 {
23 #pragma omp atomic
24 cnt3 = cnt3 + 1;
25 if (t < 3 || t > 9 || (t & 1) == 0)
26 abort ();
27 }
28
29 void
30 bar (S *p, S *o)
31 {
32 p->s = 1;
33 if (o->t != 5)
34 abort ();
35 p->t = 9;
36 }
37
38 static inline void
39 baz (S *o, S *i)
40 {
41 if (o->t != 5 || i->t != 9)
42 abort ();
43 o->s *= i->s;
44 }
45
46 #pragma omp declare reduction (+: S : omp_out.s += omp_in.s) initializer (omp_priv (0, 3))
47 #pragma omp declare reduction (*: S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
48
49 S as = { 0LL, 7 };
50 S &a = as;
51 S bs (1LL, 5);
52 S &b = bs;
53
54 void
55 foo (S &c, S &d)
56 {
57 int i;
58 for (i = 0; i < 2; i++)
59 #pragma omp task in_reduction (+: c) in_reduction (*: b, d) in_reduction (+: a)
60 {
61 a.s += 7;
62 b.s *= 2;
63 c.s += 9;
64 d.s *= 3;
65 if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
66 || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
67 abort ();
68 }
69 }
70
71 void
72 test ()
73 {
74 S cs = { 0LL, 7 };
75 S &c = cs;
76 S ds (1LL, 5);
77 #pragma omp parallel if (0)
78 {
79 S &d = ds;
80 #pragma omp parallel shared (a, b, c, d)
81 {
82 #pragma omp for schedule (static, 1) reduction (task, +: a, c) reduction (task, *: b, d)
83 for (int i = 0; i < 4; i++)
84 #pragma omp task in_reduction (*: b, d) in_reduction (+: a, c)
85 {
86 int j;
87 a.s += 7;
88 b.s *= 2;
89 for (j = 0; j < 2; j++)
90 #pragma omp task in_reduction (+: a) in_reduction (*: b) \
91 in_reduction (+: c) in_reduction (*: d)
92 {
93 a.s += 7;
94 b.s *= 2;
95 c.s += 9;
96 d.s *= 3;
97 foo (c, d);
98 if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
99 || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
100 abort ();
101 }
102 c.s += 9;
103 d.s *= 3;
104 if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
105 || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
106 abort ();
107 }
108 #define THREEP7 (3LL * 3LL * 3LL * 3LL * 3LL * 3LL * 3LL)
109 if (d.s != (THREEP7 * THREEP7 * THREEP7 * THREEP7) || d.t != 5)
110 abort ();
111 if (a.s != 28 * 7 || a.t != 7 || b.s != (1L << 28) || b.t != 5
112 || c.s != 28 * 9 || c.t != 7)
113 abort ();
114 }
115 }
116 if (a.s != 28 * 7 || a.t != 7 || b.s != (1L << 28) || b.t != 5
117 || c.s != 28 * 9 || c.t != 7)
118 abort ();
119 if (ds.s != (THREEP7 * THREEP7 * THREEP7 * THREEP7) || ds.t != 5)
120 abort ();
121 }
122
123 int
124 main ()
125 {
126 int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
127 test ();
128 if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
129 abort ();
130 }