| 1 |
#include <omp.h> |
| 2 |
#include <stdlib.h> |
| 3 |
|
| 4 |
struct S |
| 5 |
{ |
| 6 |
int a, b, c, d, e; |
| 7 |
}; |
| 8 |
typedef struct S S; |
| 9 |
|
| 10 |
int main (void) |
| 11 |
{ |
| 12 |
int d = omp_get_default_device (); |
| 13 |
int id = omp_get_initial_device (); |
| 14 |
|
| 15 |
if (d < 0 || d >= omp_get_num_devices ()) |
| 16 |
d = id; |
| 17 |
|
| 18 |
S s = { 1, 2, 3, 4, 5 }; |
| 19 |
#pragma omp target enter data map (to:s) |
| 20 |
|
| 21 |
int *p = &s.b; |
| 22 |
int *q = &s.d; |
| 23 |
#pragma omp target enter data map (alloc: p[:1], q[:1]) |
| 24 |
|
| 25 |
s.b = 88; |
| 26 |
s.d = 99; |
| 27 |
|
| 28 |
#pragma omp target exit data map (release: s) |
| 29 |
if (d != id) |
| 30 |
{ |
| 31 |
if (!omp_target_is_present (&s, d)) |
| 32 |
abort (); |
| 33 |
if (!omp_target_is_present (&p[0], d)) |
| 34 |
abort (); |
| 35 |
if (!omp_target_is_present (&q[0], d)) |
| 36 |
abort (); |
| 37 |
} |
| 38 |
|
| 39 |
#pragma omp target exit data map (from: q[:1]) |
| 40 |
if (d != id) |
| 41 |
{ |
| 42 |
if (omp_target_is_present (&s, d)) |
| 43 |
abort (); |
| 44 |
if (omp_target_is_present (&p[0], d)) |
| 45 |
abort (); |
| 46 |
if (omp_target_is_present (&q[0], d)) |
| 47 |
abort (); |
| 48 |
|
| 49 |
if (q[0] != 4) |
| 50 |
abort (); |
| 51 |
if (p[0] != 88) |
| 52 |
abort (); |
| 53 |
} |
| 54 |
|
| 55 |
return 0; |
| 56 |
} |