21 #ifndef GRPPI_NATIVE_MAPREDUCE_H 22 #define GRPPI_NATIVE_MAPREDUCE_H 51 template <
typename InputIt,
typename Result,
typename Transformer,
54 InputIt first, InputIt last, Result identity,
55 Transformer && transform_op, Combiner &&combine_op)
61 const int num_elements = last - first;
67 const auto begin = first + (elements_per_thread * i);
70 (first + elements_per_thread * (i+1));
72 tasks.emplace_back([&,begin,end,i](){
74 partial_results[i] =
map_reduce(seq, begin, end, partial_results[i],
75 forward<Transformer>(transform_op), forward<Combiner>(combine_op));
80 first,( first+elements_per_thread ), partial_results[0],
81 forward<Transformer>(transform_op),
82 forward<Combiner>(combine_op));
84 for (
auto && t : tasks) { t.join(); }
86 Result result = identity;
87 for (
auto && p : partial_results) { result = combine_op(result, p); }
Definition: callable_traits.h:24
int concurrency_degree() const noexcept
Get number of grppi trheads.
Definition: parallel_execution_native.h:178
Native parallel execution policy. This policy uses ISO C++ threads as implementation building block a...
Definition: parallel_execution_native.h:136
Result map_reduce(parallel_execution_native &ex, InputIt first, InputIt last, Result identity, Transformer &&transform_op, Combiner &&combine_op)
Invoke Map/reduce pattern on a data sequence with native parallel execution.
Definition: native/mapreduce.h:53
native_thread_manager thread_manager()
Get a manager object for registration/deregistration in the thread index table for current thread...
Definition: parallel_execution_native.h:199
Sequential execution policy.
Definition: sequential_execution.h:31