GrPPI  0.2
Generic and Reusable Parallel Pattern Interface
poly/divideconquer.h
Go to the documentation of this file.
1 
21 #ifndef GRPPI_POLY_DIVIDECONQUER_H
22 #define GRPPI_POLY_DIVIDECONQUER_H
23 
24 #include "polymorphic_execution.h"
25 #include "../common/support.h"
26 
27 namespace grppi {
28 
29 template <typename Input, typename Divider, typename Solver, typename Combiner>
30 typename std::result_of<Solver(Input)>::type
32  Input & input,
33  Divider && divide_op, Solver && solve_op,
34  Combiner && combine_op)
35 {
36  return {};
37 }
38 
39 template <typename E, typename ... O,
40  typename Input, typename Divider, typename Solver, typename Combiner,
42 typename std::result_of<Solver(Input)>::type
44  Input & input,
45  Divider && divide_op, Solver && solve_op,
46  Combiner && combine_op)
47 {
48  return divide_conquer_multi_impl<O...>(ex, input,
49  std::forward<Divider>(divide_op), std::forward<Solver>(solve_op),
50  std::forward<Combiner>(combine_op) );
51 }
52 
53 template <typename E, typename ... O,
54  typename Input, typename Divider, typename Solver, typename Combiner,
56 typename std::result_of<Solver(Input)>::type
58  Input & input,
59  Divider && divide_op, Solver && solve_op,
60  Combiner && combine_op)
61 {
62  if (typeid(E) == ex.type()) {
63  return divide_conquer(*ex.execution_ptr<E>(),
64  input,
65  std::forward<Divider>(divide_op), std::forward<Solver>(solve_op),
66  std::forward<Combiner>(combine_op));
67  }
68  else {
69  return divide_conquer_multi_impl<O...>(ex, input,
70  std::forward<Divider>(divide_op), std::forward<Solver>(solve_op),
71  std::forward<Combiner>(combine_op));
72  }
73 }
74 
97 template <typename Input, typename Divider, typename Solver, typename Combiner>
98 typename std::result_of<Solver(Input)>::type
100  Input & input,
101  Divider && divide_op, Solver && solve_op,
102  Combiner && combine_op)
103 {
109  >(ex, input,
110  std::forward<Divider>(divide_op), std::forward<Solver>(solve_op),
111  std::forward<Combiner>(combine_op));
112 }
113 
119 } // end namespace grppi
120 
121 #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
std::result_of< Solver(Input)>::type divide_conquer(parallel_execution_native &ex, Input &problem, Divider &&divide_op, Solver &&solve_op, Combiner &&combine_op)
Invoke Divide/conquer pattern with native parallel execution.
Definition: native/divideconquer.h:124
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
std::result_of< Solver(Input)>::type divide_conquer_multi_impl(polymorphic_execution &ex, Input &input, Divider &&divide_op, Solver &&solve_op, Combiner &&combine_op)
Definition: poly/divideconquer.h:31
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