1 #include <stdio.h>
2 #include <openacc.h>
3 #include <gomp-constants.h>
4 
5 #define N (32*32*32+17)
main()6 int main ()
7 {
8   int ix;
9   int ondev = 0;
10   int t = 0,  h = 0;
11   int workersize;
12 
13 #pragma acc parallel num_workers(32) vector_length(32) copy(ondev) \
14 	    copyout(workersize)
15   {
16 #pragma acc loop worker reduction(+:t)
17     for (unsigned ix = 0; ix < N; ix++)
18       {
19 	int val = ix;
20 
21 	if (acc_on_device (acc_device_not_host))
22 	  {
23 	    int g, w, v;
24 
25 	    g = __builtin_goacc_parlevel_id (GOMP_DIM_GANG);
26 	    w = __builtin_goacc_parlevel_id (GOMP_DIM_WORKER);
27 	    v = __builtin_goacc_parlevel_id (GOMP_DIM_VECTOR);
28 	    val = (g << 16) | (w << 8) | v;
29 	    ondev = 1;
30 	  }
31 	t += val;
32       }
33     workersize = __builtin_goacc_parlevel_size (GOMP_DIM_WORKER);
34   }
35 
36   for (ix = 0; ix < N; ix++)
37     {
38       int val = ix;
39       if(ondev)
40 	{
41 	  int g = 0;
42 	  int w = ix % workersize;
43 	  int v = 0;
44 
45 	  val = (g << 16) | (w << 8) | v;
46 	}
47       h += val;
48     }
49   if (t != h)
50     {
51       printf ("t=%x expected %x\n", t, h);
52       return 1;
53     }
54 
55   return 0;
56 }
57