@@ -73,34 +73,6 @@ void performMinMaxRed(int &min_val, int &max_val) {
7373 max_val = input_data[i];
7474 }
7575}
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- }
103-
10476std::complex <double > doComplexReduction (std::complex <double > *arr) {
10577 std::complex <double > result (1 , 0 );
10678
@@ -138,7 +110,8 @@ int main(void) {
138110 const float kPiVal = 3 .14f ;
139111 const int kExpectedSum = 45 ; // Sum of 0..9
140112 const int kExpectedProd = 3628800 ; // 10!
141- const float kExpectedFsum = kPiVal * N; // 3.14f * 10
113+ const float kExpectedFsum = 31 .400000f ; // 3.14f * 10
114+ const float kTolerance = 1e-4f ;
142115 const int kExpectedMin = 3 ;
143116 const int kExpectedMax = 12 ;
144117 std::complex <double > arr[N];
@@ -163,7 +136,7 @@ int main(void) {
163136 total_errors++;
164137 if (t_prod_v != kExpectedProd )
165138 total_errors++;
166- if (t_fsum_v != kExpectedFsum )
139+ if (std::abs ( t_fsum_v - kExpectedFsum ) > kTolerance )
167140 total_errors++;
168141 }
169142#pragma omp parallel num_threads(4)
@@ -177,7 +150,6 @@ int main(void) {
177150 total_errors++;
178151 }
179152 total_errors += checkUserDefinedReduction ();
180- total_errors += performComplexReduction ();
181153#pragma omp parallel num_threads(4)
182154 {
183155 std::complex <double > result (1 , 0 );
0 commit comments