[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
OpenMP question
From: |
Richard Guenther |
Subject: |
OpenMP question |
Date: |
Fri, 21 Nov 2003 23:52:09 +0100 (CET) |
Hi!
Any OpenMP experts on the table? How would one do manual reduction
parallelized with OpenMP like from Evaluator/ReductionEvaluator.h:
template<class T, class Op, class Expr, class Domain>
inline static void evaluate(T &ret, const Op &op, const Expr &e,
const Domain &domain, WrappedInt<1>)
{
Expr localExpr(e);
int e0 = domain[0].length();
T answer = ReductionTraits<Op, T>::identity();
for (int i0 = 0; i0 < e0; ++i0)
op(answer, localExpr.read(i0));
ret = answer;
}
So the first part may be easy, just(?)
T answer = ReductionTraits<Op, T>::identity();
#pragma omp parallel for private (answer)
for (int i0 = 0; i0 < e0; ++i0)
op(answer, localExpr.read(i0));
but how do the final reduction on the multiple private answer's? One cant
use the reduction functionality from OpenMP with these C++ constructs
here, sadly. The stranges version I could come up with is (I'm sure it
still won't work):
#pragma omp parallel shared (answer)
{
T answer[omp_get_num_threads()]; // is probably private now... :/
int n = omp_get_thread_num();
answer[n] = ReductionTraits<Op, T>::identity();
#pragma omp for
for (int i0 = 0; i0 < e0; ++i0)
op(answer[n], localExpr.read(i0));
#pragma omp master
{
for (int i = 1; i<omp_get_num_threads(); ++i)
op(answer[0], answer[i]);
ret = answer[0];
}
}
Any hints on doing OpenMP reductions with C++ operators here from anyone?
Thanks in advance!
Richard.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- OpenMP question,
Richard Guenther <=