================ @@ -0,0 +1,93 @@ +//RUN: %libomp-cxx-compile -fopenmp-version=60 && %libomp-run +#include <stdio.h> +#include <omp.h> +#include "omp_testsuite.h" + +#define N 10 +class Sum { + int val; + +public: + Sum(int v = 0) : val(v) {} + Sum operator+(const Sum &rhs) const { return Sum(val + rhs.val); } + Sum &operator+=(const Sum &rhs) { + val += rhs.val; + return *this; + } + int getValue() const { return val; } +}; + +// Declare OpenMP reduction +#pragma omp declare reduction(sum_reduction:Sum : omp_out += omp_in) \ + initializer(omp_priv = Sum(0)) + +int checkUserDefinedReduction() { + Sum final_result_udr(0); + Sum array_sum[N]; + int error_flag = 0; + int expected_value = 0; + for (int i = 0; i < N; ++i) { + array_sum[i] = Sum(i); + expected_value += i; // Calculate expected sum: 0 + 1 + ... + (N-1) + } +#pragma omp parallel num_threads(4) + { +#pragma omp for reduction(sum_reduction : final_result_udr) ---------------- alexey-bataev wrote:
Make reductions over 2 variables https://github.com/llvm/llvm-project/pull/134709 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits