OpenACC documentation updates.
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c / reduction-4.c
blobc8a9a6c0d36a6d6478002dfff319e3d717d12e57
1 /* { dg-do run } */
3 /* complex reductions. */
5 #include <stdlib.h>
6 #include <stdbool.h>
7 #include <math.h>
8 #include <complex.h>
10 #define vl 32
12 int
13 main(void)
15 const int n = 1000;
16 int i;
17 double complex vresult, result, array[n];
18 bool lvresult, lresult;
20 for (i = 0; i < n; i++)
21 array[i] = i;
23 result = 0;
24 vresult = 0;
26 /* '+' reductions. */
27 #pragma acc parallel vector_length (vl)
28 #pragma acc loop reduction (+:result)
29 for (i = 0; i < n; i++)
30 result += array[i];
32 /* Verify the reduction. */
33 for (i = 0; i < n; i++)
34 vresult += array[i];
36 if (result != vresult)
37 abort ();
39 result = 0;
40 vresult = 0;
42 /* Needs support for complex multiplication. */
44 // /* '*' reductions. */
45 // #pragma acc parallel vector_length (vl)
46 // #pragma acc loop reduction (*:result)
47 // for (i = 0; i < n; i++)
48 // result *= array[i];
49 //
50 // /* Verify the reduction. */
51 // for (i = 0; i < n; i++)
52 // vresult *= array[i];
53 //
54 // if (fabs(result - vresult) > .0001)
55 // abort ();
56 // result = 0;
57 // vresult = 0;
59 // /* 'max' reductions. */
60 // #pragma acc parallel vector_length (vl)
61 // #pragma acc loop reduction (+:result)
62 // for (i = 0; i < n; i++)
63 // result = result > array[i] ? result : array[i];
64 //
65 // /* Verify the reduction. */
66 // for (i = 0; i < n; i++)
67 // vresult = vresult > array[i] ? vresult : array[i];
68 //
69 // printf("%d != %d\n", result, vresult);
70 // if (result != vresult)
71 // abort ();
72 //
73 // result = 0;
74 // vresult = 0;
75 //
76 // /* 'min' reductions. */
77 // #pragma acc parallel vector_length (vl)
78 // #pragma acc loop reduction (+:result)
79 // for (i = 0; i < n; i++)
80 // result = result < array[i] ? result : array[i];
81 //
82 // /* Verify the reduction. */
83 // for (i = 0; i < n; i++)
84 // vresult = vresult < array[i] ? vresult : array[i];
85 //
86 // printf("%d != %d\n", result, vresult);
87 // if (result != vresult)
88 // abort ();
90 result = 5;
91 vresult = 5;
93 lresult = false;
94 lvresult = false;
96 /* '&&' reductions. */
97 #pragma acc parallel vector_length (vl)
98 #pragma acc loop reduction (&&:lresult)
99 for (i = 0; i < n; i++)
100 lresult = lresult && (creal(result) > creal(array[i]));
102 /* Verify the reduction. */
103 for (i = 0; i < n; i++)
104 lvresult = lresult && (creal(result) > creal(array[i]));
106 if (lresult != lvresult)
107 abort ();
109 result = 5;
110 vresult = 5;
112 lresult = false;
113 lvresult = false;
115 /* '||' reductions. */
116 #pragma acc parallel vector_length (vl)
117 #pragma acc loop reduction (||:lresult)
118 for (i = 0; i < n; i++)
119 lresult = lresult || (creal(result) > creal(array[i]));
121 /* Verify the reduction. */
122 for (i = 0; i < n; i++)
123 lvresult = lresult || (creal(result) > creal(array[i]));
125 if (lresult != lvresult)
126 abort ();
128 return 0;