| 1 |
#include <stdlib.h> |
| 2 |
#include <assert.h> |
| 3 |
|
| 4 |
struct st { |
| 5 |
int *p; |
| 6 |
}; |
| 7 |
|
| 8 |
int main (void) |
| 9 |
{ |
| 10 |
struct st s[2]; |
| 11 |
s[0].p = (int *) calloc (5, sizeof (int)); |
| 12 |
s[1].p = (int *) calloc (5, sizeof (int)); |
| 13 |
|
| 14 |
/* These mappings not supported by the OpenMP spec, and are currently |
| 15 |
implemented as an extension by GCC for legacy compatibility only. See |
| 16 |
e.g. OpenMP 5.2, "5.8.3 map Clause": |
| 17 |
|
| 18 |
"If multiple list items are explicitly mapped on the same construct and |
| 19 |
have the same containing array or have base pointers that share original |
| 20 |
storage, and if any of the list items do not have corresponding list |
| 21 |
items that are present in the device data environment prior to a task |
| 22 |
encountering the construct, then the list items must refer to the same |
| 23 |
array elements of either the containing array or the implicit array of |
| 24 |
the base pointers." |
| 25 |
*/ |
| 26 |
|
| 27 |
#pragma omp target map(s[0].p, s[1].p, s[0].p[0:2], s[1].p[1:3]) |
| 28 |
{ |
| 29 |
s[0].p[0] = 5; |
| 30 |
s[1].p[1] = 7; |
| 31 |
} |
| 32 |
|
| 33 |
#pragma omp target map(s, s[0].p[0:2], s[1].p[1:3]) |
| 34 |
{ |
| 35 |
s[0].p[0]++; |
| 36 |
s[1].p[1]++; |
| 37 |
} |
| 38 |
|
| 39 |
#pragma omp target map(s[0:2], s[0].p[0:2], s[1].p[1:3]) |
| 40 |
{ |
| 41 |
s[0].p[0]++; |
| 42 |
s[1].p[1]++; |
| 43 |
} |
| 44 |
|
| 45 |
assert (s[0].p[0] == 7); |
| 46 |
assert (s[1].p[1] == 9); |
| 47 |
|
| 48 |
free (s[0].p); |
| 49 |
free (s[1].p); |
| 50 |
return 0; |
| 51 |
} |