GrPPI  0.2
Generic and Reusable Parallel Pattern Interface
poly/mapreduce.h
Go to the documentation of this file.
1 
21 #ifndef GRPPI_POLY_MAPREDUCE_H
22 #define GRPPI_POLY_MAPREDUCE_H
23 
24 #include "polymorphic_execution.h"
25 #include "../common/support.h"
26 
27 namespace grppi {
28 
29 template <typename InputIt, typename Transformer, typename Identity, typename Combiner>
30 Identity map_reduce_multi_impl(polymorphic_execution & e, InputIt first, InputIt last,
31  Identity identity, Transformer && transform_op, Combiner && combine_op)
32 {
33  return {};
34 }
35 
36 template <typename E, typename ... O,
37  typename InputIt, typename Transformer, typename Identity, typename Combiner,
39 Identity map_reduce_multi_impl(polymorphic_execution & e, InputIt first, InputIt last,
40  Identity identity, Transformer && transform_op, Combiner && combine_op)
41 {
42  return map_reduce_multi_impl<O...>(e, first, last, identity, std::forward<Transformer>(transform_op),
43  std::forward<Combiner>(combine_op));
44 }
45 
46 template <typename E, typename ... O,
47  typename InputIt, typename Transformer, typename Identity, typename Combiner,
49 Identity map_reduce_multi_impl(polymorphic_execution & e, InputIt first, InputIt last, Identity identity,
50  Transformer && transform_op, Combiner && combine_op)
51 {
52  if (typeid(E) == e.type()) {
53  return map_reduce(*e.execution_ptr<E>(),
54  first, last, identity, std::forward<Transformer>(transform_op),
55  std::forward<Combiner>(combine_op));
56  }
57  else {
58  return map_reduce_multi_impl<O...>(e, first, last, identity, std::forward<Transformer>(transform_op),
59  std::forward<Combiner>(combine_op));
60  }
61 }
62 
86 template <typename InputIt, typename Transformer, typename Result,
87  typename Combiner>
89  InputIt first, InputIt last, Result identity,
90  Transformer && transform_op,
91  Combiner && combine_op)
92 {
93  return map_reduce_multi_impl<
98  >(ex, first, last, identity, std::forward<Transformer>(transform_op),
99  std::forward<Combiner>(combine_op));
100 }
101 
108 } // end namespace grppi
109 
110 #endif
Definition: callable_traits.h:24
Native parallel execution policy. This policy uses ISO C++ threads as implementation building block a...
Definition: parallel_execution_native.h:136
const std::type_info & type() const noexcept
Definition: polymorphic_execution.h:77
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
std::enable_if_t< is_supported< E >(), int > requires_execution_supported
Definition: support.h:32
OpenMP parallel execution policy.
Definition: parallel_execution_omp.h:40
TBB parallel execution policy.
Definition: parallel_execution_tbb.h:37
E * execution_ptr()
Get the execution pointer for a given type.
Definition: polymorphic_execution.h:91
Sequential execution policy.
Definition: sequential_execution.h:31
Definition: polymorphic_execution.h:63
std::enable_if_t<!is_supported< E >(), int > requires_execution_not_supported
Definition: support.h:36
Identity map_reduce_multi_impl(polymorphic_execution &e, InputIt first, InputIt last, Identity identity, Transformer &&transform_op, Combiner &&combine_op)
Definition: poly/mapreduce.h:30