GrPPI  0.2
Generic and Reusable Parallel Pattern Interface
poly/farm.h
Go to the documentation of this file.
1 
22 #ifndef GRPPI_POLY_FARM_H
23 #define GRPPI_POLY_FARM_H
24 
25 #include "polymorphic_execution.h"
26 #include "../common/support.h"
27 
28 namespace grppi {
29 
30 template <typename Generator, typename Consumer>
31 void farm_multi_impl(polymorphic_execution & ex, Generator generate_op,
32  Consumer consume_op)
33 {
34 }
35 
36 
37 template <typename Generator, typename Transformer, typename Consumer>
38 void farm_multi_impl(polymorphic_execution & ex, Generator generate_op,
39  Transformer transform_op, Consumer consume_op)
40 {
41 }
42 
43 template <typename E, typename ... O, typename Generator, typename Transformer,
45 void farm_multi_impl(polymorphic_execution & ex, Generator && generate_op,
46  Transformer && transform_op)
47 {
48  farm_multi_impl<O...>(ex, std::forward<Generator>(generate_op),
49  std::forward<Transformer>(transform_op));
50 }
51 
52 template <typename E, typename ... O, typename Generator, typename Transformer,
53  typename Consumer,
54  internal::requires_execution_not_supported<E> = 0>
55 void farm_multi_impl(polymorphic_execution & ex, Generator && generate_op,
56  Transformer && transform_op, Consumer && consume_op)
57 {
58  farm_multi_impl<O...>(ex, std::forward<Generator>(generate_op),
59  std::forward<Transformer>(transform_op),
60  std::forward<Consumer>(consume_op));
61 }
62 
63 
64 
65 template <typename E, typename ... O, typename Generator, typename Consumer,
67 void farm_multi_impl(polymorphic_execution & ex, Generator && generate_op,
68  Consumer && consume_op)
69 {
70  if (typeid(E) == ex.type()) {
71  farm(*ex.execution_ptr<E>(), std::forward<Generator>(generate_op),
72  std::forward<Consumer>(consume_op));
73  }
74  else {
75  farm_multi_impl<O...>(ex, std::forward<Generator>(generate_op),
76  std::forward<Consumer>(consume_op));
77  }
78 }
79 
80 
81 template <typename E, typename ... O, typename Generator, typename Transformer, typename Consumer,
82  internal::requires_execution_supported<E> = 0>
83 void farm_multi_impl(polymorphic_execution & ex, Generator && generate_op,
84  Transformer && transform_op, Consumer && consume_op)
85 {
86  if (typeid(E) == ex.type()) {
87  farm(*ex.execution_ptr<E>(), std::forward<Generator>(generate_op),
88  std::forward<Transformer>(transform_op),
89  std::forward<Consumer>(consume_op));
90  }
91  else {
92  farm_multi_impl<O...>(ex, std::forward<Generator>(generate_op),
93  std::forward<Transformer>(transform_op),
94  std::forward<Consumer>(consume_op));
95  }
96 }
97 
98 
116 template <typename Generator, typename Consumer>
117 void farm(polymorphic_execution & ex, Generator && generate_op,
118  Consumer && consume_op)
119 {
125  >(ex, std::forward<Generator>(generate_op),
126  std::forward<Consumer>(consume_op));
127 }
128 
140 template <typename Generator, typename Transformer, typename Consumer>
141 void farm(polymorphic_execution & ex, Generator && generate_op,
142  Transformer && transform_op, Consumer && consume_op)
143 {
149  >(ex, std::forward<Generator>(generate_op),
150  std::forward<Transformer>(transform_op),
151  std::forward<Consumer>(consume_op));
152 }
153 
154 } // end namespace grppi
155 
156 #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::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
auto farm(Execution &ex, Transformer &&transform_op)
Invoke Farm pattern on a data stream that can be composed in other streaming patterns.
Definition: farm.h:51
std::enable_if_t<!is_supported< E >(), int > requires_execution_not_supported
Definition: support.h:36
void farm_multi_impl(polymorphic_execution &ex, Generator generate_op, Consumer consume_op)
Definition: poly/farm.h:31