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
|
#include <omp.h>
#include <stdlib.h>
struct S
{
int a, b, c, d;
};
typedef struct S S;
int main (void)
{
int d = omp_get_default_device ();
int id = omp_get_initial_device ();
if (d < 0 || d >= omp_get_num_devices ())
d = id;
S s;
#pragma omp target enter data map (alloc: s)
#pragma omp target enter data map (alloc: s)
#pragma omp target exit data map (release: s.a)
#pragma omp target exit data map (release: s.b)
/* OpenMP 5.0 structure element mapping rules describe that elements of same
structure variable should allocate/deallocate in a uniform fashion, so
all elements of 's' should be removed together by above 'exit data's. */
if (d != id)
{
if (omp_target_is_present (&s, d))
abort ();
if (omp_target_is_present (&s.a, d))
abort ();
if (omp_target_is_present (&s.b, d))
abort ();
if (omp_target_is_present (&s.c, d))
abort ();
if (omp_target_is_present (&s.d, d))
abort ();
}
#pragma omp target enter data map (alloc: s.a, s.b)
#pragma omp target enter data map (alloc: s.a)
#pragma omp target enter data map (alloc: s.b)
#pragma omp target exit data map (release: s)
#pragma omp target exit data map (release: s)
#pragma omp target exit data map (release: s)
/* OpenMP 5.0 structure element mapping rules describe that elements of same
structure variable should allocate/deallocate in a uniform fashion, so
all elements of 's' should be removed together by above 'exit data's. */
if (d != id)
{
if (omp_target_is_present (&s, d))
abort ();
if (omp_target_is_present (&s.a, d))
abort ();
if (omp_target_is_present (&s.b, d))
abort ();
if (omp_target_is_present (&s.c, d))
abort ();
if (omp_target_is_present (&s.d, d))
abort ();
}
return 0;
}
|