Skip gnat.dg/prot7.adb on hppa.
[official-gcc.git] / libgomp / testsuite / libgomp.c-c++-common / task-reduction-2.c
blobaad725c29e34f5c99b059525f29b692d54fe998b
1 #ifdef __cplusplus
2 extern "C"
3 #endif
4 void abort (void);
6 struct S { long int s, t; };
8 void
9 bar (struct S *p, struct S *o)
11 p->s = 1;
12 if (o->t != 5)
13 abort ();
14 p->t = 9;
17 static inline void
18 baz (struct S *o, struct S *i)
20 if (o->t != 5 || i->t != 9)
21 abort ();
22 o->s *= i->s;
25 #pragma omp declare reduction (+: struct S : omp_out.s += omp_in.s) initializer (omp_priv = { 0, 3 })
26 #pragma omp declare reduction (*: struct S : baz (&omp_out, &omp_in)) initializer (bar (&omp_priv, &omp_orig))
28 struct S a = { 0, 7 };
29 struct S b = { 1, 5 };
31 void
32 foo (void)
34 int i;
35 for (i = 0; i < 2; i++)
36 #pragma omp task in_reduction (*: b) in_reduction (+: a)
38 a.s += 7;
39 b.s *= 2;
40 if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9))
41 abort ();
45 int
46 main ()
48 struct S c = { 0, 7 };
49 #pragma omp parallel
50 #pragma omp single
52 struct S d = { 1, 5 };
53 #pragma omp taskgroup task_reduction (+: a, c) task_reduction (*: b, d)
55 int i;
56 for (i = 0; i < 4; i++)
57 #pragma omp task in_reduction (*: b, d) in_reduction (+: a, c)
59 int j;
60 a.s += 7;
61 b.s *= 2;
62 for (j = 0; j < 2; j++)
63 #pragma omp task in_reduction (+: a) in_reduction (*: b) \
64 in_reduction (+: c) in_reduction (*: d)
66 a.s += 7;
67 b.s *= 2;
68 c.s += 9;
69 d.s *= 3;
70 foo ();
71 if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
72 || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
73 abort ();
75 c.s += 9;
76 d.s *= 3;
77 if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9)
78 || (c.t != 7 && c.t != 3) || (d.t != 5 && d.t != 9))
79 abort ();
82 #define THREEP4 (3L * 3L * 3L * 3L)
83 if (d.s != (THREEP4 * THREEP4 * THREEP4) || d.t != 5)
84 abort ();
86 if (a.s != 28 * 7 || a.t != 7 || b.s != (1L << 28) || b.t != 5
87 || c.s != 12 * 9 || c.t != 7)
88 abort ();
89 return 0;