| 1 |
/* { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } } */ |
| 2 |
|
| 3 |
#include <assert.h> |
| 4 |
#include <openacc.h> |
| 5 |
#include <stdint.h> |
| 6 |
|
| 7 |
#define N 128 |
| 8 |
|
| 9 |
int |
| 10 |
main () |
| 11 |
{ |
| 12 |
int *ptrarr[N]; |
| 13 |
int otherarr[N]; |
| 14 |
int sum = 0, hostsum = 0; |
| 15 |
|
| 16 |
for (int i = 0; i < N; i++) |
| 17 |
{ |
| 18 |
otherarr[i] = i * 2 + 1; |
| 19 |
ptrarr[i] = &otherarr[N - 1 - i]; |
| 20 |
hostsum += otherarr[i]; |
| 21 |
} |
| 22 |
|
| 23 |
acc_copyin (otherarr, sizeof otherarr); |
| 24 |
acc_copyin (ptrarr, sizeof ptrarr); |
| 25 |
|
| 26 |
for (int i = 0; i < N; i++) |
| 27 |
{ |
| 28 |
#pragma acc enter data attach(ptrarr[i]) |
| 29 |
} |
| 30 |
|
| 31 |
#pragma acc parallel loop copyin(ptrarr[0:N], otherarr[0:N]) \ |
| 32 |
reduction(+:sum) |
| 33 |
for (int i = 0; i < N; i++) |
| 34 |
sum += *ptrarr[i]; |
| 35 |
|
| 36 |
for (int i = 0; i < N; i++) |
| 37 |
{ |
| 38 |
#pragma acc exit data detach(ptrarr[i]) |
| 39 |
} |
| 40 |
|
| 41 |
assert (sum == hostsum); |
| 42 |
|
| 43 |
acc_delete (ptrarr, sizeof ptrarr); |
| 44 |
acc_delete (otherarr, sizeof otherarr); |
| 45 |
|
| 46 |
return 0; |
| 47 |
} |
| 48 |
|