| 1 |
/* { dg-do run } */ |
| 2 |
|
| 3 |
#include <stdlib.h> |
| 4 |
#include <assert.h> |
| 5 |
|
| 6 |
#define N 1024 |
| 7 |
#define M 64 |
| 8 |
|
| 9 |
int main (void) |
| 10 |
{ |
| 11 |
int *a_orig[N]; |
| 12 |
int *(&a)[N] = a_orig; |
| 13 |
|
| 14 |
for (int i = 0; i < N; i++) |
| 15 |
a[i] = (int *) calloc (M, sizeof (int)); |
| 16 |
|
| 17 |
/* 'target enter data'/'target exit data' with array of pointers. */ |
| 18 |
#pragma omp target enter data map(alloc: a[0:N]) |
| 19 |
|
| 20 |
for (int i = 0; i < N; i++) |
| 21 |
{ |
| 22 |
#pragma omp target enter data map(to: a[i][0:M]) |
| 23 |
} |
| 24 |
|
| 25 |
#pragma omp target map(alloc: a) |
| 26 |
{ |
| 27 |
for (int i = 0; i < N; i++) |
| 28 |
for (int j = 0; j < M; j++) |
| 29 |
a[i][j] = i + j; |
| 30 |
} |
| 31 |
|
| 32 |
for (int i = 0; i < N; i++) |
| 33 |
{ |
| 34 |
#pragma omp target exit data map(release: a[i]) map(from: a[i][0:M]) |
| 35 |
} |
| 36 |
|
| 37 |
#pragma omp target exit data map(release: a, a[0:N]) |
| 38 |
|
| 39 |
/* 'target data' with array of pointers. */ |
| 40 |
#pragma omp target data map(alloc: a[0:N]) |
| 41 |
{ |
| 42 |
#pragma omp target data map(tofrom: a[5][0:M]) |
| 43 |
{ |
| 44 |
#pragma omp target map(alloc: a) |
| 45 |
{ |
| 46 |
for (int i = 0; i < M; i++) |
| 47 |
a[5][i]++; |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
/* 'target' with array of pointers. */ |
| 53 |
#pragma omp target data map(alloc: a[0:N]) |
| 54 |
{ |
| 55 |
#pragma omp target map(tofrom: a[7][0:M]) |
| 56 |
{ |
| 57 |
for (int i = 0; i < M; i++) |
| 58 |
a[7][i] += 2; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
for (int i = 0; i < N; i++) |
| 63 |
for (int j = 0; j < M; j++) |
| 64 |
assert (a[i][j] == i + j + (i == 5) + 2 * (i == 7)); |
| 65 |
|
| 66 |
for (int i = 0; i < N; i++) |
| 67 |
free (a[i]); |
| 68 |
|
| 69 |
return 0; |
| 70 |
} |