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 "-Wopenacc-parallelism" } for testing/documenting
5 aspects of that functionality. */
6
7 #include <assert.h>
8 #include <openacc.h>
9
10 int
11 main (int argc, char *argv[])
12 {
13 int res, res1 = 0, res2 = 0;
14
15 #if defined(ACC_DEVICE_TYPE_host)
16 # define GANGS 1
17 #else
18 # define GANGS 256
19 #endif
20 #pragma acc parallel num_gangs(GANGS) num_workers(32) vector_length(32) \
21 reduction(+:res1) copy(res1, res2) async(1)
22 /* { dg-bogus "warning: region is gang partitioned but does not contain gang partitioned code" "TODO 'reduction', 'atomic'" { xfail { ! openacc_host_selected } } .-2 } */
23 /* { dg-warning "region is worker partitioned but does not contain worker partitioned code" "" { target *-*-* } .-3 } */
24 /* { dg-warning "region is vector partitioned but does not contain vector partitioned code" "" { target *-*-* } .-4 } */
25 {
26 res1 += 5;
27
28 #pragma acc atomic
29 res2 += 5;
30 }
31 res = GANGS * 5;
32
33 acc_async_wait (1);
34
35 assert (res == res1);
36 assert (res == res2);
37 #undef GANGS
38
39 res = res1 = res2 = 1;
40
41 #if defined(ACC_DEVICE_TYPE_host)
42 # define GANGS 1
43 #else
44 # define GANGS 8
45 #endif
46 #pragma acc parallel num_gangs(GANGS) num_workers(32) vector_length(32) \
47 reduction(*:res1) copy(res1, res2) async(1)
48 /* { dg-bogus "warning: region is gang partitioned but does not contain gang partitioned code" "TODO 'reduction', 'atomic'" { xfail { ! openacc_host_selected } } .-2 } */
49 /* { dg-warning "region is worker partitioned but does not contain worker partitioned code" "" { target *-*-* } .-3 } */
50 /* { dg-warning "region is vector partitioned but does not contain vector partitioned code" "" { target *-*-* } .-4 } */
51 {
52 res1 *= 5;
53
54 #pragma acc atomic
55 res2 *= 5;
56 }
57 for (int i = 0; i < GANGS; ++i)
58 res *= 5;
59
60 acc_async_wait_all ();
61
62 assert (res == res1);
63 assert (res == res2);
64
65 return 0;
66 }