1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
void
foo (int x, int *y, int n, int v)
{
int z[3] = { 45, 46, 47 };
int u[n], w[n], i;
for (i = 0; i < n; i++)
w[i] = u[i] = n + i;
#pragma omp taskgroup task_reduction (+: x, y[:2], z[1:2], u, w[1:v])
{
#pragma omp task in_reduction (+: x, y[:2], z[1:2], u, w[1:v])
{
x++;
y[0] += 2;
y[1] += 3;
z[1] += 4;
u[0] += 5;
w[1] += 6;
}
#pragma omp target in_reduction (+: x, y[:2], z[1:2], u, w[1:v])
{
x += 4;
y[0] += 5;
y[1] += 6;
z[2] += 7;
u[1] += 8;
w[2] += 7;
}
#pragma omp target in_reduction (+: x, y[:v], z[1:v], u, w[1:2])
{
x += 9;
y[0] += 10;
y[1] += 11;
z[1] += 12;
u[2] += 13;
w[1] += 14;
}
}
if (x != 56 || y[0] != 60 || y[1] != 64)
__builtin_abort ();
if (z[0] != 45 || z[1] != 62 || z[2] != 54)
__builtin_abort ();
if (u[0] != 8 || u[1] != 12 || u[2] != 18)
__builtin_abort ();
if (w[0] != 3 || w[1] != 24 || w[2] != 12)
__builtin_abort ();
}
void
bar (int x, int *y, int n, int v)
{
int z[3] = { 45, 46, 47 };
int u[n], w[n], i;
for (i = 0; i < n; i++)
w[i] = u[i] = n + i;
#pragma omp parallel master
#pragma omp taskgroup task_reduction (+: x, y[:2], z[1:2], u, w[1:v])
{
#pragma omp task in_reduction (+: x, y[:2], z[1:2], u, w[1:v])
{
x++;
y[0] += 2;
y[1] += 3;
z[1] += 4;
u[0] += 5;
w[1] += 6;
}
#pragma omp target in_reduction (+: x, y[:2], z[1:2], u, w[1:v])
{
x += 4;
y[0] += 5;
y[1] += 6;
z[2] += 7;
u[1] += 8;
w[2] += 7;
}
#pragma omp target in_reduction (+: x, y[:v], z[1:v], u, w[1:2])
{
x += 9;
y[0] += 10;
y[1] += 11;
z[1] += 12;
u[2] += 13;
w[1] += 14;
}
}
if (x != 56 || y[0] != 77 || y[1] != 84)
__builtin_abort ();
if (z[0] != 45 || z[1] != 62 || z[2] != 54)
__builtin_abort ();
if (u[0] != 8 || u[1] != 12 || u[2] != 18)
__builtin_abort ();
if (w[0] != 3 || w[1] != 24 || w[2] != 12)
__builtin_abort ();
}
int
main ()
{
int y[2] = { 43, 44 };
#pragma omp parallel master
foo (42, y, 3, 2);
bar (42, y, 3, 2);
return 0;
}
|