Fix xfail for 32-bit hppa*-*-* in gcc.dg/pr84877.c
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / taskloop-reduction-1.C
blobf7fb9cac9e53f546038aa5b5943d16e4e43bd5f9
1 extern "C" void abort ();
3 struct S { S (); S (unsigned long long int, int); ~S (); static int cnt1, cnt2, cnt3; unsigned long long int s; int 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 (unsigned long long int x, 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 rbar (S *p, S *o)
32   p->s = 1;
33   if (o->t != 5)
34     abort ();
35   p->t = 9;
38 static inline void
39 rbaz (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) \
47   initializer (omp_priv (0, 3))
48 #pragma omp declare reduction (*: S : rbaz (&omp_out, &omp_in)) \
49   initializer (rbar (&omp_priv, &omp_orig))
51 S gs = { 0, 7 };
52 S &g = gs;
53 S hs (1, 5);
54 S &h = hs;
56 int
57 foo (int *a, int &b)
59   int xs = 0;
60   int &x = xs;
61   #pragma omp taskloop reduction (+:x) in_reduction (+:b)
62   for (int i = 0; i < 64; i++)
63     {
64       x += a[i];
65       b += a[i] * 2;
66     }
67   return x;
70 unsigned long long int
71 bar (int *a, unsigned long long int &b)
73   unsigned long long int xs = 1;
74   unsigned long long int &x = xs;
75   #pragma omp taskloop reduction (*:x) in_reduction (*:b)
76   for (int i = 0; i < 64; i++)
77     {
78       #pragma omp task in_reduction (*:x)
79       x *= a[i];
80       #pragma omp task in_reduction (*:b)
81       b *= (3 - a[i]);
82     }
83   return x;
86 void
87 baz (int i, int *a, int *c)
89   #pragma omp task in_reduction (*:h) in_reduction (+:g)
90   {
91     g.s += 7 * a[i];
92     h.s *= (3 - c[i]);
93     if ((g.t != 7 && g.t != 3) || (h.t != 5 && h.t != 9))
94       abort ();
95   }
98 void
99 test ()
101   int i, j, a[64], b = 0, c[64];
102   unsigned long long int d = 1, e;
103   S ms (0, 7);
104   for (i = 0; i < 64; i++)
105     {
106       a[i] = 2 * i;
107       c[i] = 1 + ((i % 3) != 1);
108     }
109   #pragma omp parallel
110   #pragma omp master
111   {
112     S ns = { 1, 5 };
113     S &m = ms;
114     S &n = ns;
115     #pragma omp taskgroup task_reduction (+:b)
116       j = foo (a, b);
117     #pragma omp taskgroup task_reduction (*:d)
118       e = bar (c, d);
119     #pragma omp taskloop reduction (+: g, m) reduction (*: h, n)
120     for (i = 0; i < 64; ++i)
121       {
122         g.s += 3 * a[i];
123         h.s *= (3 - c[i]);
124         m.s += 4 * a[i];
125         n.s *= c[i];
126         if ((g.t != 7 && g.t != 3) || (h.t != 5 && h.t != 9)
127             || (m.t != 7 && m.t != 3) || (n.t != 5 && n.t != 9))
128           abort ();
129         baz (i, a, c);
130       }
131     if (n.s != (1ULL << 43) || n.t != 5)
132       abort ();
133   }
134   if (j != 63 * 64 || b != 63 * 64 * 2)
135     abort ();
136   if (e != (1ULL << 43) || d != (1ULL << 21))
137     abort ();
138   if (g.s != 63 * 64 * 10 || g.t != 7)
139     abort ();
140   if (h.s != (1ULL << 42) || h.t != 5)
141     abort ();
142   if (ms.s != 63 * 64 * 4 || ms.t != 7)
143     abort ();
147 main ()
149   int c1 = S::cnt1, c2 = S::cnt2, c3 = S::cnt3;
150   test ();
151   if (S::cnt1 + S::cnt2 - c1 - c2 != S::cnt3 - c3)
152     abort ();