libgomp/
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / reduction-1.c
blobe8a8911faeb11e6a4191e43d5a79bbd2b6d1262f
1 /* { dg-do run } */
3 /* Ignore vector_length warnings for offloaded (nvptx) targets. */
4 /* { dg-additional-options "-foffload=-w" } */
6 /* Integer reductions. */
8 #include <stdlib.h>
9 #include "reduction.h"
11 const int ng = 8;
12 const int nw = 4;
13 const int vl = 32;
15 static void
16 test_reductions (void)
18 const int n = 10;
19 int i;
20 int array[n];
22 for (i = 0; i < n; i++)
23 array[i] = i+1;
25 /* Gang reductions. */
26 check_reduction_op (int, +, 0, array[i], num_gangs (ng), gang);
27 check_reduction_op (int, *, 1, array[i], num_gangs (ng), gang);
28 check_reduction_op (int, &, -1, array[i], num_gangs (ng), gang);
29 check_reduction_op (int, |, 0, array[i], num_gangs (ng), gang);
30 check_reduction_op (int, ^, 0, array[i], num_gangs (ng), gang);
32 /* Worker reductions. */
33 check_reduction_op (int, +, 0, array[i], num_workers (nw), worker);
34 check_reduction_op (int, *, 1, array[i], num_workers (nw), worker);
35 check_reduction_op (int, &, -1, array[i], num_workers (nw), worker);
36 check_reduction_op (int, |, 0, array[i], num_workers (nw), worker);
37 check_reduction_op (int, ^, 0, array[i], num_workers (nw), worker);
39 /* Vector reductions. */
40 check_reduction_op (int, +, 0, array[i], vector_length (vl), vector);
41 check_reduction_op (int, *, 1, array[i], vector_length (vl), vector);
42 check_reduction_op (int, &, -1, array[i], vector_length (vl), vector);
43 check_reduction_op (int, |, 0, array[i], vector_length (vl), vector);
44 check_reduction_op (int, ^, 0, array[i], vector_length (vl), vector);
46 /* Combined reductions. */
47 check_reduction_op (int, +, 0, array[i], num_gangs (ng) num_workers (nw)
48 vector_length (vl), gang worker vector);
49 check_reduction_op (int, *, 1, array[i], num_gangs (ng) num_workers (nw)
50 vector_length (vl), gang worker vector);
51 check_reduction_op (int, &, -1, array[i], num_gangs (ng) num_workers (nw)
52 vector_length (vl), gang worker vector);
53 check_reduction_op (int, |, 0, array[i], num_gangs (ng) num_workers (nw)
54 vector_length (vl), gang worker vector);
55 check_reduction_op (int, ^, 0, array[i], num_gangs (ng) num_workers (nw)
56 vector_length (vl), gang worker vector);
59 static void
60 test_reductions_bool (void)
62 const int n = 1000;
63 int i;
64 int array[n];
65 int cmp_val;
67 for (i = 0; i < n; i++)
68 array[i] = i;
70 cmp_val = 5;
72 /* Gang reductions. */
73 check_reduction_op (int, &&, 1, (cmp_val > array[i]), num_gangs (ng),
74 gang);
75 check_reduction_op (int, ||, 0, (cmp_val > array[i]), num_gangs (ng),
76 gang);
78 /* Worker reductions. */
79 check_reduction_op (int, &&, 1, (cmp_val > array[i]), num_workers (nw),
80 worker);
81 check_reduction_op (int, ||, 0, (cmp_val > array[i]), num_workers (nw),
82 worker);
84 /* Vector reductions. */
85 check_reduction_op (int, &&, 1, (cmp_val > array[i]), vector_length (vl),
86 vector);
87 check_reduction_op (int, ||, 0, (cmp_val > array[i]), vector_length (vl),
88 vector);
90 /* Combined reductions. */
91 check_reduction_op (int, &&, 1, (cmp_val > array[i]), num_gangs (ng)
92 num_workers (nw) vector_length (vl), gang worker vector);
93 check_reduction_op (int, ||, 0, (cmp_val > array[i]), num_gangs (ng)
94 num_workers (nw) vector_length (vl), gang worker vector);
97 static void
98 test_reductions_minmax (void)
100 const int n = 1000;
101 int i;
102 int array[n];
104 for (i = 0; i < n; i++)
105 array[i] = i;
107 /* Gang reductions. */
108 check_reduction_macro (int, min, n + 1, array[i], num_gangs (ng), gang);
109 check_reduction_macro (int, max, -1, array[i], num_gangs (ng), gang);
111 /* Worker reductions. */
112 check_reduction_macro (int, min, n + 1, array[i], num_workers (nw), worker);
113 check_reduction_macro (int, max, -1, array[i], num_workers (nw), worker);
115 /* Vector reductions. */
116 check_reduction_macro (int, min, n + 1, array[i], vector_length (vl),
117 vector);
118 check_reduction_macro (int, max, -1, array[i], vector_length (vl), vector);
120 /* Combined reductions. */
121 check_reduction_macro (int, min, n + 1, array[i], num_gangs (ng)
122 num_workers (nw) vector_length (vl), gang worker
123 vector);
124 check_reduction_macro (int, max, -1, array[i], num_gangs (ng)
125 num_workers (nw) vector_length (vl), gang worker
126 vector);
130 main (void)
132 test_reductions ();
133 test_reductions_bool ();
134 test_reductions_minmax ();
135 return 0;