1 const int n = 100;
2 
3 int
private_reduction()4 private_reduction ()
5 {
6   int i, r;
7 
8   #pragma acc parallel
9   #pragma acc loop private (r) reduction (+:r)
10   for (i = 0; i < 100; i++)
11     r += 10;
12 
13   return r;
14 }
15 
16 int
parallel_reduction()17 parallel_reduction ()
18 {
19   int sum = 0;
20   int dummy = 0;
21 
22 #pragma acc data copy (dummy)
23   {
24 #pragma acc parallel num_gangs (10) copy (sum) reduction (+:sum)
25     {
26       int v = 5;
27       sum += 10 + v;
28     }
29   }
30 
31   return sum;
32 }
33 
34 int
main()35 main ()
36 {
37   int i, s = 0;
38 
39 #pragma acc parallel num_gangs (10) copy (s) reduction (+:s)
40   for (i = 0; i < n; i++)
41     s += i+1;
42 
43 #pragma acc parallel num_gangs (10) reduction (+:s) copy (s)
44   for (i = 0; i < n; i++)
45     s += i+1;
46 
47   return 0;
48 }
49