static typename WDP::ReductionType parallel_reduce(int begin, int end, WDP wd) { typename WDP::ReductionType result = wd.identity(); for (int i=begin; i != end; ++i) { result = wd.reduce( result, wd.generate(i) ); } return result; }
void tpi_reduction_work(TPI_Work * work) { const WDPPlusRange<WDP>* wdp_wrapper = static_cast<const WDPPlusRange<WDP>*>(work->info); int beg = wdp_wrapper->beg, end = wdp_wrapper->end; WDP wdp = wdp_wrapper->wdp; int ibeg, iend; tpi_work_span(work, beg, end, ibeg, iend); typedef typename WDP::ReductionType ReductionType; ReductionType tmpi; ReductionType &res = *(static_cast<ReductionType*>(work->reduce)); for (int i=ibeg; i<iend; ++i) { tmpi = wdp.generate(i); res = wdp.reduce(res, tmpi); } }