6 main (int argc
, char **argv
)
8 int N
= 128; //1024 * 1024;
9 float *a
, *b
, *c
, *d
, *e
;
13 nbytes
= N
* sizeof (float);
15 a
= (float *) malloc (nbytes
);
16 b
= (float *) malloc (nbytes
);
17 c
= (float *) malloc (nbytes
);
18 d
= (float *) malloc (nbytes
);
19 e
= (float *) malloc (nbytes
);
21 for (i
= 0; i
< N
; i
++)
27 #pragma acc enter data copyin (a[0:N]) copyin (b[0:N]) copyin (N) async
28 #pragma acc parallel async wait
30 for (i
= 0; i
< N
; i
++)
33 #pragma acc update host (a[0:N], b[0:N]) async wait
36 for (i
= 0; i
< N
; i
++)
45 for (i
= 0; i
< N
; i
++)
51 #pragma acc update device (a[0:N], b[0:N]) async (1)
52 #pragma acc parallel async (1)
54 for (i
= 0; i
< N
; i
++)
57 #pragma acc update host (a[0:N], b[0:N]) async (1) wait (1)
60 for (i
= 0; i
< N
; i
++)
69 for (i
= 0; i
< N
; i
++)
77 #pragma acc update device (a[0:N]) async (1)
78 #pragma acc update device (b[0:N]) async (2)
79 #pragma acc enter data copyin (c[0:N], d[0:N]) async (3)
81 #pragma acc parallel async (1) wait (1,2)
83 for (i
= 0; i
< N
; i
++)
84 b
[i
] = (a
[i
] * a
[i
] * a
[i
]) / a
[i
];
86 #pragma acc parallel async (2) wait (1,3)
88 for (i
= 0; i
< N
; i
++)
89 c
[i
] = (a
[i
] + a
[i
] + a
[i
] + a
[i
]) / a
[i
];
91 #pragma acc parallel async (3) wait (1,3)
93 for (i
= 0; i
< N
; i
++)
94 d
[i
] = ((a
[i
] * a
[i
] + a
[i
]) / a
[i
]) - a
[i
];
96 #pragma acc update host (a[0:N], b[0:N], c[0:N], d[0:N]) async (1) wait (1,2,3)
99 for (i
= 0; i
< N
; i
++)
114 for (i
= 0; i
< N
; i
++)
123 #pragma acc update device (a[0:N], b[0:N], c[0:N], d[0:N]) async (1)
124 #pragma acc enter data copyin (e[0:N]) async (5)
126 #pragma acc parallel async (1) wait (1)
127 for (int ii
= 0; ii
< N
; ii
++)
128 b
[ii
] = (a
[ii
] * a
[ii
] * a
[ii
]) / a
[ii
];
130 #pragma acc parallel async (2) wait (1)
131 for (int ii
= 0; ii
< N
; ii
++)
132 c
[ii
] = (a
[ii
] + a
[ii
] + a
[ii
] + a
[ii
]) / a
[ii
];
134 #pragma acc parallel async (3) wait (1)
135 for (int ii
= 0; ii
< N
; ii
++)
136 d
[ii
] = ((a
[ii
] * a
[ii
] + a
[ii
]) / a
[ii
]) - a
[ii
];
138 #pragma acc parallel wait (1,5) async (4)
139 for (int ii
= 0; ii
< N
; ii
++)
140 e
[ii
] = a
[ii
] + b
[ii
] + c
[ii
] + d
[ii
];
142 #pragma acc exit data copyout (a[0:N]) copyout (b[0:N]) copyout (c[0:N]) copyout (d[0:N]) copyout (e[0:N]) wait (1, 2, 3, 4) async (1)
143 #pragma acc exit data delete (N)
147 for (i
= 0; i
< N
; i
++)