1 #include <assert.h>
2
3 /* Test of reduction on both parallel and loop directives (workers and vectors
4 together in gang-partitioned mode, float type). */
5
6 int
7 main (int argc, char *argv[])
8 {
9 int i, j;
10 float arr[32768];
11 float res = 0, hres = 0;
12
13 for (i = 0; i < 32768; i++)
14 arr[i] = i % (32768 / 64);
15
16 #pragma acc parallel num_gangs(32) num_workers(32) vector_length(32) \
17 reduction(+:res) copy(res)
18 {
19 #pragma acc loop gang /* { dg-warning "nested loop in reduction needs reduction clause for 'res'" "TODO" } */
20 for (j = 0; j < 32; j++)
21 {
22 #pragma acc loop worker vector reduction(+:res)
23 for (i = 0; i < 1024; i++)
24 res += arr[j * 1024 + i];
25
26 #pragma acc loop worker vector reduction(+:res)
27 for (i = 0; i < 1024; i++)
28 res += arr[j * 1024 + (1023 - i)];
29 }
30 }
31
32 for (j = 0; j < 32; j++)
33 for (i = 0; i < 1024; i++)
34 {
35 hres += arr[j * 1024 + i];
36 hres += arr[j * 1024 + (1023 - i)];
37 }
38
39 assert (hres <= 16777216);
40 assert (res == hres);
41
42 return 0;
43 }