1 /* Test of reduction on parallel directive (with async).  */
2 /* See also Fortran variants in "../libgomp.oacc-fortran/par-reduction-2*".  */
3 
4 /* { dg-additional-options "-w" } */
5 
6 #include <assert.h>
7 #include <openacc.h>
8 
9 int
main(int argc,char * argv[])10 main (int argc, char *argv[])
11 {
12   int res, res1 = 0, res2 = 0;
13 
14 #if defined(ACC_DEVICE_TYPE_host)
15 # define GANGS 1
16 #else
17 # define GANGS 256
18 #endif
19   #pragma acc parallel num_gangs(GANGS) num_workers(32) vector_length(32) \
20     reduction(+:res1) copy(res1, res2) async(1)
21   {
22     res1 += 5;
23 
24     #pragma acc atomic
25     res2 += 5;
26   }
27   res = GANGS * 5;
28 
29   acc_async_wait (1);
30 
31   assert (res == res1);
32   assert (res == res2);
33 #undef GANGS
34 
35   res = res1 = res2 = 1;
36 
37 #if defined(ACC_DEVICE_TYPE_host)
38 # define GANGS 1
39 #else
40 # define GANGS 8
41 #endif
42   #pragma acc parallel num_gangs(GANGS) num_workers(32) vector_length(32) \
43     reduction(*:res1) copy(res1, res2) async(1)
44   {
45     res1 *= 5;
46 
47     #pragma acc atomic
48     res2 *= 5;
49   }
50   for (int i = 0; i < GANGS; ++i)
51     res *= 5;
52 
53   acc_async_wait_all ();
54 
55   assert (res == res1);
56   assert (res == res2);
57 
58   return 0;
59 }
60