aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c-c++-common/reduction-6.c
blob: 62e81506bddaa1fcf1f588ffff48c0443a5fd5e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/* { dg-additional-options "-foffload-options=nvptx-none=-latomic" { target { offload_target_nvptx } } } */
/* C / C++'s logical AND and OR operators take any scalar argument
   which compares (un)equal to 0 - the result 1 or 0 and of type int.

   In this testcase, the int result is again converted to an integer complex
   type.

   While having a floating-point/complex array element with || and && can make
   sense, having a complex reduction variable is odd but valid.

   Test: int complex reduction variable + int complex array.
         as reduction-4.c but with target.  */

#define N 1024
_Complex char rcc[N];
_Complex short rcs[N];
_Complex int rci[N];
_Complex long long rcl[N];

int
reduction_or ()
{
  _Complex char orc = 0;
  _Complex short ors = 0;
  _Complex int ori = 0;
  _Complex long orl = 0;

  #pragma omp target parallel reduction(||: orc) map(orc)
  for (int i=0; i < N; ++i)
    orc = orc || rcl[i];

  #pragma omp target parallel for reduction(||: ors) map(ors)
  for (int i=0; i < N; ++i)
    ors = ors || rci[i];

  #pragma omp target parallel for simd reduction(||: ori) map(ori)
  for (int i=0; i < N; ++i)
    ori = ori || rcs[i];

  #pragma omp target parallel loop reduction(||: orl) map(orl)
  for (int i=0; i < N; ++i)
    orl = orl || rcc[i];

  return __real__ (orc + ors + ori + orl) + __imag__ (orc + ors + ori + orl);
}

int
reduction_or_teams ()
{
  _Complex char orc = 0;
  _Complex short ors = 0;
  _Complex int ori = 0;
  _Complex long orl = 0;

  #pragma omp target teams distribute parallel for reduction(||: orc) map(orc)
  for (int i=0; i < N; ++i)
    orc = orc || rcc[i];

  #pragma omp target teams distribute parallel for simd reduction(||: ors) map(ors)
  for (int i=0; i < N; ++i)
    ors = ors || rcs[i];

  #pragma omp target teams distribute parallel for reduction(||: ori) map(ori)
  for (int i=0; i < N; ++i)
    ori = ori || rci[i];

  #pragma omp target teams distribute parallel for simd reduction(||: orl) map(orl)
  for (int i=0; i < N; ++i)
    orl = orl || rcl[i];

  return __real__ (orc + ors + ori + orl) + __imag__ (orc + ors + ori + orl);
}

int
reduction_and ()
{
  _Complex char andc = 1;
  _Complex short ands = 1;
  _Complex int andi = 1;
  _Complex long andl = 1;

  #pragma omp target parallel reduction(&&: andc) map(andc)
  for (int i=0; i < N; ++i)
    andc = andc && rcc[i];

  #pragma omp target parallel for reduction(&&: ands) map(ands)
  for (int i=0; i < N; ++i)
    ands = ands && rcs[i];

  #pragma omp target parallel for simd reduction(&&: andi) map(andi)
  for (int i=0; i < N; ++i)
    andi = andi && rci[i];

  #pragma omp target parallel loop reduction(&&: andl) map(andl)
  for (int i=0; i < N; ++i)
    andl = andl && rcl[i];

  return __real__ (andc + ands + andi + andl)
	 + __imag__ (andc + ands + andi + andl);
}

int
reduction_and_teams ()
{
  _Complex char andc = 1;
  _Complex short ands = 1;
  _Complex int andi = 1;
  _Complex long andl = 1;

  #pragma omp target teams distribute parallel for reduction(&&: andc) map(andc)
  for (int i=0; i < N; ++i)
    andc = andc && rcl[i];

  #pragma omp target teams distribute parallel for simd reduction(&&: ands) map(ands)
  for (int i=0; i < N; ++i)
    ands = ands && rci[i];

  #pragma omp target teams distribute parallel for reduction(&&: andi) map(andi)
  for (int i=0; i < N; ++i)
    andi = andi && rcs[i];

  #pragma omp target teams distribute parallel for simd reduction(&&: andl) map(andl)
  for (int i=0; i < N; ++i)
    andl = andl && rcc[i];

  return __real__ (andc + ands + andi + andl)
	 + __imag__ (andc + ands + andi + andl);
}

int
main ()
{
  for (int i = 0; i < N; ++i)
    {
      rcc[i] = 0;
      rcs[i] = 0;
      rci[i] = 0;
      rcl[i] = 0;
    }

  if (reduction_or () != 0)
    __builtin_abort ();
  if (reduction_or_teams () != 0)
    __builtin_abort ();
  if (reduction_and () != 0)
    __builtin_abort ();
  if (reduction_and_teams () != 0)
    __builtin_abort ();

  rcc[10] = 1.0;
  rcs[15] = 1.0i;
  rci[10] = 1.0;
  rcl[15] = 1.0i;

  if (reduction_or () != 4)
    __builtin_abort ();
  if (reduction_or_teams () != 4)
    __builtin_abort ();
  if (reduction_and () != 0)
    __builtin_abort ();
  if (reduction_and_teams () != 0)
    __builtin_abort ();

  for (int i = 0; i < N; ++i)
    {
      rcc[i] = 1;
      rcs[i] = 1i;
      rci[i] = 1;
      rcl[i] = 1 + 1i;
    }

  if (reduction_or () != 4)
    __builtin_abort ();
  if (reduction_or_teams () != 4)
    __builtin_abort ();
  if (reduction_and () != 4)
    __builtin_abort ();
  if (reduction_and_teams () != 4)
    __builtin_abort ();

  rcc[10] = 0.0;
  rcs[15] = 0.0;
  rci[10] = 0.0;
  rcl[15] = 0.0;

  if (reduction_or () != 4)
    __builtin_abort ();
  if (reduction_or_teams () != 4)
    __builtin_abort ();
  if (reduction_and () != 0)
    __builtin_abort ();
  if (reduction_and_teams () != 0)
    __builtin_abort ();

  return 0;
}