Skip to content

Commit 0c2978c

Browse files
author
Chandra Ghale
committed
complex type test for priv redn
1 parent a0d29ab commit 0c2978c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

openmp/runtime/test/worksharing/for/omp_for_private_reduction.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <stdio.h>
33
#include <omp.h>
44
#include <limits.h>
5+
#include <complex.h>
6+
#include <math.h>
57
#include "omp_testsuite.h"
68

79
#define N 10
@@ -71,6 +73,33 @@ void performMinMaxRed(int &min_val, int &max_val) {
7173
max_val = input_data[i];
7274
}
7375
}
76+
int performComplexReduction() {
77+
double _Complex arr[N];
78+
double _Complex expected = 0.0 + 0.0 * I;
79+
double _Complex result = 0.0 + 0.0 * I;
80+
int error = 0;
81+
82+
// Initialize the array and compute serial sum
83+
for (int i = 0; i < N; ++i) {
84+
arr[i] = i - i * I;
85+
expected += arr[i];
86+
}
87+
double real_sum = 0.0, imag_sum = 0.0;
88+
#pragma omp parallel private(real_sum) private(imag_sum)
89+
{
90+
#pragma omp for reduction(+ : real_sum, imag_sum)
91+
for (int i = 0; i < N; ++i) {
92+
real_sum += creal(arr[i]);
93+
imag_sum += cimag(arr[i]);
94+
}
95+
96+
result = real_sum + imag_sum * I;
97+
if (cabs(result - expected) > 1e-6) {
98+
error++;
99+
}
100+
}
101+
return error;
102+
}
74103
void performReductions(int n_elements, const int *input_values,
75104
int &sum_val_out, int &prod_val_out,
76105
float &float_sum_val_out) {
@@ -126,6 +155,7 @@ int main(void) {
126155
total_errors++;
127156
}
128157
total_errors += checkUserDefinedReduction();
158+
total_errors += performComplexReduction();
129159
if (total_errors != 0)
130160
fprintf(stderr, "ERROR: reduction on private variable %d\n", total_errors);
131161

0 commit comments

Comments
 (0)