Skip to content

Commit 4df2910

Browse files
author
Chandra Ghale
committed
update test
1 parent ad0d2f0 commit 4df2910

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %libomp-cxx-compile -fopenmp-version=60 && %libomp-run
22
#include <stdio.h>
33
#include <omp.h>
4+
#include <limits.h>
45
#include "omp_testsuite.h"
56

67
#define N 10
@@ -42,7 +43,20 @@ int checkUserDefinedReduction() {
4243
}
4344
return error_flag;
4445
}
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+
}
4660
void performReductions(int n_elements, const int *input_values,
4761
int &sum_val_out, int &prod_val_out,
4862
float &float_sum_val_out) {
@@ -68,6 +82,8 @@ int main(void) {
6882
const int kExpectedSum = 45; // Sum of 0..9
6983
const int kExpectedProd = 3628800; // 10!
7084
const float kExpectedFsum = kPiVal * N; // 3.14f * 10
85+
const int kExpectedMin = 3;
86+
const int kExpectedMax = 12;
7187

7288
for (int i = 0; i < N; i++)
7389
input_array[i] = i;
@@ -85,6 +101,16 @@ int main(void) {
85101
if (t_fsum_v != kExpectedFsum)
86102
total_errors++;
87103
}
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+
}
88114
total_errors += checkUserDefinedReduction();
89115
if (total_errors != 0)
90116
fprintf(stderr, "ERROR: reduction on private variable %d\n", total_errors);

0 commit comments

Comments
 (0)