1 // RUN: %libomptarget-compile-generic -O3 && %libomptarget-run-generic | %fcheck-generic
9 void reset_input(double *a
, double *a_h
, double *b
, double *c
) {
10 for(int i
= 0 ; i
< MAX_N
; i
++) {
17 int main(int argc
, char *argv
[]) {
18 double *a
= (double *)calloc(MAX_N
, sizeof(double));
19 double *a_h
= (double *)calloc(MAX_N
, sizeof(double));
20 double *d
= (double *)calloc(MAX_N
, sizeof(double));
21 double *d_h
= (double *)calloc(MAX_N
, sizeof(double));
22 double *b
= (double *)calloc(MAX_N
, sizeof(double));
23 double *c
= (double *)calloc(MAX_N
, sizeof(double));
25 #pragma omp target enter data map(to:a[:MAX_N],b[:MAX_N],c[:MAX_N],d[:MAX_N])
27 for (int n
= 32 ; n
< MAX_N
; n
+=5000) {
28 reset_input(a
, a_h
, b
, c
);
30 #pragma omp target update to(a[:n],b[:n],c[:n],d[:n])
32 for (int tms
= 1 ; tms
<= 256 ; tms
*= 2) { // 8 times
33 for (int ths
= 32 ; ths
<= 1024 ; ths
*= 2) { // 6 times
36 #pragma omp teams num_teams(tms) thread_limit(ths)
38 #pragma omp distribute parallel for
39 for (int i
= 0; i
< n
; ++i
) {
42 #pragma omp distribute parallel for
43 for (int i
= 0; i
< n
; ++i
) {
50 // check results for each 'n'
51 for (int times
= 0 ; times
< t
; times
++) {
52 for (int i
= 0; i
< n
; ++i
) {
53 a_h
[i
] += b
[i
] + c
[i
];
55 for (int i
= 0; i
< n
; ++i
)
56 d_h
[i
] -= b
[i
] + c
[i
];
58 #pragma omp target update from(a[:n],d[:n])
60 for (int i
= 0; i
< n
; ++i
) {
62 printf("A Error at n = %d, i = %d: host = %f, device = %f\n", n
, i
, a_h
[i
], a
[i
]);
66 printf("D Error at n = %d, i = %d: host = %lf, device = %lf\n", n
, i
, d_h
[i
], d
[i
]);
73 printf("Succeeded\n");