21 #ifndef GRPPI_NATIVE_REDUCE_H 22 #define GRPPI_NATIVE_REDUCE_H 50 template <
typename InputIt,
typename Identity,
typename Combiner>
52 InputIt first, InputIt last,
54 Combiner && combine_op)
56 auto identityVal = identity;
58 int numElements = last - first;
60 std::atomic<int> finishedTask(1);
62 std::vector<typename std::iterator_traits<InputIt>::value_type> out(ex.
concurrency_degree());
65 auto begin = first + (elemperthr * i);
66 auto end = first + (elemperthr * (i+1));
69 [&](InputIt begin, InputIt end,
int tid){
70 out[tid] = identityVal;
71 for( ; begin != end; begin++ ) {
72 out[tid] = combine_op(out[tid], *begin );
76 std::move(begin), std::move(end), i
80 auto end = first + elemperthr;
82 for(;first!=end;first++){
83 out[0] = combine_op( out[0], *first);
89 for(
unsigned int i = 1; i < out.size(); i++){
90 outVal = combine_op(outVal, out[i]);
Definition: callable_traits.h:24
int concurrency_degree() const noexcept
Get number of grppi trheads.
Definition: parallel_execution_native.h:178
void create_task(T task)
Definition: pool.h:43
thread_pool pool
Thread pool for lanching workers.
Definition: parallel_execution_native.h:235
Native parallel execution policy. This policy uses ISO C++ threads as implementation building block a...
Definition: parallel_execution_native.h:136
auto reduce(parallel_execution_native &ex, InputIt first, InputIt last, Identity identity, Combiner &&combine_op)
Invoke Reduce pattern with identity value on a data sequence with parallel native execution...
Definition: native/reduce.h:51