GrPPI  0.2
Generic and Reusable Parallel Pattern Interface
poly/reduce.h
Go to the documentation of this file.
1 
21 #ifndef GRPPI_POLY_REDUCE_H
22 #define GRPPI_POLY_REDUCE_H
23 
24 #include "polymorphic_execution.h"
25 #include "../common/support.h"
26 
27 namespace grppi {
28 
29 template <typename InputIt, typename Identity, typename Combiner>
31  InputIt first, InputIt last,
32  Identity identity,
33  Combiner &&combine_op) -> decltype(combine_op(*first,*first))
34 {
35  return {};
36 }
37 
38 
39 
40 template <typename E, typename ... O,
41  typename InputIt, typename Identity, typename Combiner,
44  InputIt first, InputIt last,
45  Identity identity,
46  Combiner && combine_op)
47 {
48  return reduce_multi_impl<O...>(ex, first, last, identity, std::forward<Combiner>(combine_op));
49 }
50 
51 
52 
53 template <typename E, typename ... O,
54  typename InputIt, typename Identity, typename Combiner,
57  InputIt first, InputIt last,
58  Identity identity,
59  Combiner &&combine_op)
60 {
61  if (typeid(E) == ex.type()) {
62  return reduce(*ex.execution_ptr<E>(),
63  first, last, identity, std::forward<Combiner>(combine_op));
64  }
65  else {
66  return reduce_multi_impl<O...>(ex, first, last, identity, std::forward<Combiner>(combine_op));
67  }
68 }
69 
91 template <typename InputIt, typename Identity, typename Combiner>
93  InputIt first, InputIt last,
94  Identity identity,
95  Combiner &&combine_op)
96 {
97  return reduce_multi_impl<
102  >(e, first, last, identity, std::forward<Combiner>(combine_op));
103 }
104 
110 } // end namespace grppi
111 
112 #endif
Definition: callable_traits.h:24
auto reduce_multi_impl(polymorphic_execution &ex, InputIt first, InputIt last, Identity identity, Combiner &&combine_op) -> decltype(combine_op(*first,*first))
Definition: poly/reduce.h:30
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
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
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