blob: aba4f42653921a7b4a84c0f0d5385c4a660ac10f (
plain)
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
|
// { dg-do run }
#include <cstdlib>
#include <cassert>
#define N 64
struct points
{
double *x;
double *y;
double *z;
size_t len;
};
#pragma omp declare mapper(points p) map(to:p.x, p.y, p.z) \
map(p.x[0:p.len]) \
map(p.y[0:p.len]) \
map(p.z[0:p.len])
struct shape
{
points tmp;
points *pts;
int metadata[128];
};
#pragma omp declare mapper(shape s) map(tofrom:s.pts, *s.pts) map(alloc:s.tmp)
void
alloc_points (points *pts, size_t sz)
{
pts->x = new double[sz];
pts->y = new double[sz];
pts->z = new double[sz];
pts->len = sz;
for (int i = 0; i < sz; i++)
pts->x[i] = pts->y[i] = pts->z[i] = 0;
}
int main (int argc, char *argv[])
{
shape myshape;
points mypts;
myshape.pts = &mypts;
alloc_points (&myshape.tmp, N);
myshape.pts = new points;
alloc_points (myshape.pts, N);
#pragma omp target map(myshape)
{
for (int i = 0; i < N; i++)
{
myshape.pts->x[i]++;
myshape.pts->y[i]++;
myshape.pts->z[i]++;
}
}
for (int i = 0; i < N; i++)
{
assert (myshape.pts->x[i] == 1);
assert (myshape.pts->y[i] == 1);
assert (myshape.pts->z[i] == 1);
}
#pragma omp target
{
for (int i = 0; i < N; i++)
{
myshape.pts->x[i]++;
myshape.pts->y[i]++;
myshape.pts->z[i]++;
}
}
for (int i = 0; i < N; i++)
{
assert (myshape.pts->x[i] == 2);
assert (myshape.pts->y[i] == 2);
assert (myshape.pts->z[i] == 2);
}
return 0;
}
|