1
1
// RUN: %libomp-cxx-compile -fopenmp-version=60 && %libomp-run
2
2
#include < stdio.h>
3
3
#include < omp.h>
4
+ #include < limits.h>
4
5
#include " omp_testsuite.h"
5
6
6
7
#define N 10
@@ -42,7 +43,20 @@ int checkUserDefinedReduction() {
42
43
}
43
44
return error_flag;
44
45
}
45
-
46
+ void performMinMaxRed (int &min_val, int &max_val) {
47
+ int input_data[] = {7 , 3 , 12 , 5 , 8 };
48
+ int n_size = sizeof (input_data) / sizeof (input_data[0 ]);
49
+ min_val = INT_MAX;
50
+ max_val = INT_MIN;
51
+ #pragma omp for reduction(original(private), min : min_val) \
52
+ reduction (original (private), max : max_val)
53
+ for (int i = 0 ; i < n_size; ++i) {
54
+ if (input_data[i] < min_val)
55
+ min_val = input_data[i];
56
+ if (input_data[i] > max_val)
57
+ max_val = input_data[i];
58
+ }
59
+ }
46
60
void performReductions (int n_elements, const int *input_values,
47
61
int &sum_val_out, int &prod_val_out,
48
62
float &float_sum_val_out) {
@@ -68,6 +82,8 @@ int main(void) {
68
82
const int kExpectedSum = 45 ; // Sum of 0..9
69
83
const int kExpectedProd = 3628800 ; // 10!
70
84
const float kExpectedFsum = kPiVal * N; // 3.14f * 10
85
+ const int kExpectedMin = 3 ;
86
+ const int kExpectedMax = 12 ;
71
87
72
88
for (int i = 0 ; i < N; i++)
73
89
input_array[i] = i;
@@ -85,6 +101,16 @@ int main(void) {
85
101
if (t_fsum_v != kExpectedFsum )
86
102
total_errors++;
87
103
}
104
+ #pragma omp parallel num_threads(4)
105
+ {
106
+ int t_min_v;
107
+ int t_max_v;
108
+ performMinMaxRed (t_min_v, t_max_v);
109
+ if (t_min_v != kExpectedMin )
110
+ total_errors++;
111
+ if (t_max_v != kExpectedMax )
112
+ total_errors++;
113
+ }
88
114
total_errors += checkUserDefinedReduction ();
89
115
if (total_errors != 0 )
90
116
fprintf (stderr, " ERROR: reduction on private variable %d\n " , total_errors);
0 commit comments