145
|
1 #ifdef __cplusplus
|
|
2 extern "C"
|
|
3 #endif
|
|
4 void abort (void);
|
|
5
|
|
6 struct S { long int s, t; };
|
|
7
|
|
8 void
|
|
9 bar (struct S *p, struct S *o)
|
|
10 {
|
|
11 p->s = 1;
|
|
12 if (o->t != 5)
|
|
13 abort ();
|
|
14 p->t = 9;
|
|
15 }
|
|
16
|
|
17 static inline void
|
|
18 baz (struct S *o, struct S *i)
|
|
19 {
|
|
20 if (o->t != 5 || i->t != 9)
|
|
21 abort ();
|
|
22 o->s *= i->s;
|
|
23 }
|
|
24
|
|
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))
|
|
27
|
|
28 struct S a = { 0, 7 };
|
|
29 struct S b = { 1, 5 };
|
|
30
|
|
31 void
|
|
32 foo (void)
|
|
33 {
|
|
34 int i;
|
|
35 for (i = 0; i < 2; i++)
|
|
36 #pragma omp task in_reduction (*: b) in_reduction (+: a)
|
|
37 {
|
|
38 a.s += 7;
|
|
39 b.s *= 2;
|
|
40 if ((a.t != 7 && a.t != 3) || (b.t != 5 && b.t != 9))
|
|
41 abort ();
|
|
42 }
|
|
43 }
|
|
44
|
|
45 int
|
|
46 main ()
|
|
47 {
|
|
48 struct S c = { 0, 7 };
|
|
49 #pragma omp parallel
|
|
50 #pragma omp single
|
|
51 {
|
|
52 struct S d = { 1, 5 };
|
|
53 #pragma omp taskgroup task_reduction (+: a, c) task_reduction (*: b, d)
|
|
54 {
|
|
55 int i;
|
|
56 for (i = 0; i < 4; i++)
|
|
57 #pragma omp task in_reduction (*: b, d) in_reduction (+: a, c)
|
|
58 {
|
|
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)
|
|
65 {
|
|
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 ();
|
|
74 }
|
|
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 ();
|
|
80 }
|
|
81 }
|
|
82 #define THREEP4 (3L * 3L * 3L * 3L)
|
|
83 if (d.s != (THREEP4 * THREEP4 * THREEP4) || d.t != 5)
|
|
84 abort ();
|
|
85 }
|
|
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;
|
|
90 }
|