| 1 |
#include <stdlib.h> |
| 2 |
|
| 3 |
/* Test asyncronous attach and detach operation. */ |
| 4 |
|
| 5 |
typedef struct { |
| 6 |
int *a; |
| 7 |
int *b; |
| 8 |
} mystruct; |
| 9 |
|
| 10 |
int |
| 11 |
main (int argc, char* argv[]) |
| 12 |
{ |
| 13 |
const int N = 1024; |
| 14 |
mystruct m; |
| 15 |
int i; |
| 16 |
|
| 17 |
m.a = (int *) malloc (N * sizeof (int)); |
| 18 |
m.b = (int *) malloc (N * sizeof (int)); |
| 19 |
|
| 20 |
for (i = 0; i < N; i++) |
| 21 |
{ |
| 22 |
m.a[i] = 0; |
| 23 |
m.b[i] = 0; |
| 24 |
} |
| 25 |
|
| 26 |
#pragma acc enter data copyin(m) |
| 27 |
|
| 28 |
for (int i = 0; i < 99; i++) |
| 29 |
{ |
| 30 |
int j; |
| 31 |
#pragma acc parallel loop copy(m.a[0:N]) async(i % 2) |
| 32 |
for (j = 0; j < N; j++) |
| 33 |
m.a[j]++; |
| 34 |
#pragma acc parallel loop copy(m.b[0:N]) async((i + 1) % 2) |
| 35 |
for (j = 0; j < N; j++) |
| 36 |
m.b[j]++; |
| 37 |
} |
| 38 |
|
| 39 |
#pragma acc exit data copyout(m) wait(0, 1) |
| 40 |
|
| 41 |
for (i = 0; i < N; i++) |
| 42 |
{ |
| 43 |
if (m.a[i] != 99) |
| 44 |
abort (); |
| 45 |
if (m.b[i] != 99) |
| 46 |
abort (); |
| 47 |
} |
| 48 |
|
| 49 |
free (m.a); |
| 50 |
free (m.b); |
| 51 |
|
| 52 |
return 0; |
| 53 |
} |