libstdc++: AIX xfail for_overwrite.cc testcase
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / task-reduction-2.C
blob75d2ee37e4fc43dcd215fb88eb491f9c76e620a2
1 extern "C" void abort ();
3 struct S { S (); S (long int, long int); ~S (); static int cnt1, cnt2, cnt3; long int s, t; };
5 int S::cnt1;
6 int S::cnt2;
7 int S::cnt3;
9 S::S ()
11   #pragma omp atomic
12   cnt1++;
15 S::S (long int x, long int y) : s (x), t (y)
17   #pragma omp atomic update
18   ++cnt2;
21 S::~S ()
23   #pragma omp atomic
24   cnt3 = cnt3 + 1;
25   if (t < 3 || t > 9 || (t & 1) == 0)
26     abort ();
29 void
30 bar (S *p, S *o)
32   p->s = 1;
33   if (o->t != 5)
34     abort ();
35   p->t = 9;
38 static inline void
39 baz (S *o, S *i)
41   if (o->t != 5 || i->t != 9)
42     abort ();
43   o->s *= i->s;
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))
49 S a = { 0, 7 };
50 S b (1, 5);
52 void
53 foo ()
55   int i;
56   for (i = 0; i < 2; i++)
57     #pragma omp task in_reduction (*: b) in_reduction (+: a)
58     {
59       a.s += 7;
60       b.s *= 2;
61       if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9))
62         abort ();
63     }
66 void
67 test ()
69   S c = { 0, 7 };
70   #pragma omp parallel
71   #pragma omp single
72   {
73     S d (1, 5);
74     #pragma omp taskgroup task_reduction (+: a, c) task_reduction (*: b, d)
75     {
76       int i;
77       for (i = 0; i < 4; i++)
78         #pragma omp task in_reduction (*: b, d) in_reduction (+: a, c)
79         {
80           int j;
81           a.s += 7;
82           b.s *= 2;
83           for (j = 0; j < 2; j++)
84             #pragma omp task in_reduction (+: a) in_reduction (*: b) \
85                              in_reduction (+: c) in_reduction (*: d)
86             {
87               a.s += 7;
88               b.s *= 2;
89               c.s += 9;
90               d.s *= 3;
91               foo ();
92               if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
93                   || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
94                 abort ();
95             }
96           c.s += 9;
97           d.s *= 3;
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     }
103 #define THREEP4 (3L * 3L * 3L * 3L)
104     if (d.s != (THREEP4 * THREEP4 * THREEP4) || d.t != 5)
105       abort ();
106   }
107   if (a.s != 28 * 7 || a.t != 7 || b.s != (1L << 28) || b.t != 5
108       || c.s != 12 * 9 || c.t != 7)
109     abort ();
113 main ()
115   int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
116   test ();
117   if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
118     abort ();