Update 'Q' constraint documentation.
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / loop-red-gwv-1.c
blob0bec6e19510a5ceff8d7fee94634f27f35517ef6
1 #include <stdio.h>
2 #include <openacc.h>
3 #include <gomp-constants.h>
5 #define N (32*32*32+17)
6 int main ()
8 int ix;
9 int ondev = 0;
10 int t = 0, h = 0;
12 #pragma acc parallel num_gangs(32) num_workers(32) vector_length(32) copy(ondev)
14 #pragma acc loop gang worker vector reduction(+:t)
15 for (unsigned ix = 0; ix < N; ix++)
17 int val = ix;
19 if (acc_on_device (acc_device_not_host))
21 int g, w, v;
23 g = __builtin_goacc_parlevel_id (GOMP_DIM_GANG);
24 w = __builtin_goacc_parlevel_id (GOMP_DIM_WORKER);
25 v = __builtin_goacc_parlevel_id (GOMP_DIM_VECTOR);
26 val = (g << 16) | (w << 8) | v;
27 ondev = 1;
29 t += val;
33 for (ix = 0; ix < N; ix++)
35 int val = ix;
36 if(ondev)
38 int chunk_size = (N + 32*32*32 - 1) / (32*32*32);
40 int g = ix / (chunk_size * 32 * 32);
41 int w = ix / 32 % 32;
42 int v = ix % 32;
44 val = (g << 16) | (w << 8) | v;
46 h += val;
48 if (t != h)
50 printf ("t=%x expected %x\n", t, h);
51 return 1;
54 return 0;