GrPPI  0.2
Generic and Reusable Parallel Pattern Interface
poly/stream_iteration.h
Go to the documentation of this file.
1 
21 #ifndef GRPPI_POLY_STREAM_ITERATOR_H
22 #define GRPPI_POLY_STREAM_ITERATOR_H
23 
24 #include "polymorphic_execution.h"
25 #include "../common/support.h"
26 
27 namespace grppi {
28 
29 template<typename Generator, typename Predicate, typename Consumer,
30  typename Transformer >
32  farm_info<polymorphic_execution,Transformer> && op, Predicate && predicate_op, Consumer && out)
33 {
34 }
35 
36 template <typename E, typename ... O,
37  typename Generator, typename Predicate, typename Consumer,
38  typename Transformer ,
41  pipeline_info<polymorphic_execution,Transformer> && op, Predicate && predicate_op, Consumer && out)
42 {
43  repeat_until_multi_impl<O...>(e, std::forward<Generator>(in),
44  std::forward<farm_info<polymorphic_execution,Transformer> >(op), std::forward<Predicate>(predicate_op),
45  std::forward<Consumer>(out));
46 }
47 
48 template <class E, typename ... O,
49  typename Generator, typename Predicate, typename Consumer,
50  typename Transformer ,
53  farm_info<polymorphic_execution,Transformer> && op, Predicate && predicate_op, Consumer && out)
54 {
55  if (typeid(E) == e.type() && typeid(E) == op.exectype.type()) {
56  auto & pipe_exec = op.exectype;
57  auto & actual_exec = *pipe_exec. template execution_ptr<E>();
58  auto transformed_farm = farm(actual_exec, std::forward<Transformer>(op.task));
60  std::forward<Generator>(in),
61  std::forward<farm_info<E,Transformer> >(transformed_farm), std::forward<Predicate>(predicate_op),
62  std::forward<Consumer>(out));
63  }
64  else {
65  repeat_until_multi_impl<O...>(e, std::forward<Generator>(in),
66  std::forward<farm_info<polymorphic_execution,Transformer> >(op), std::forward<Predicate>(predicate_op),
67  std::forward<Consumer>(out));
68  }
69 }
70 
71 template<typename Generator, typename Predicate, typename Consumer,
72  typename ...MoreTransformers >
74  pipeline_info<polymorphic_execution,MoreTransformers...> && op, Predicate && predicate_op, Consumer && out)
75 {
76 }
77 
78 template <typename E, typename ... O,
79  typename Generator, typename Predicate, typename Consumer,
80  typename ...MoreTransformers ,
81  internal::requires_execution_not_supported<E> = 0>
83  pipeline_info<polymorphic_execution,MoreTransformers...> && op, Predicate && predicate_op, Consumer && out)
84 {
85  repeat_until_multi_impl<O...>(e, std::forward<Generator>(in),
86  std::forward<pipeline_info<polymorphic_execution,MoreTransformers...> >(op), std::forward<Predicate>(predicate_op),
87  std::forward<Consumer>(out));
88 }
89 
90 template <class E, typename ... O,
91  typename Generator, typename Predicate, typename Consumer,
92  typename ...MoreTransformers ,
93  internal::requires_execution_supported<E> = 0>
94 void repeat_until_multi_impl(polymorphic_execution & e, Generator && in,
95  pipeline_info<polymorphic_execution,MoreTransformers...> && op, Predicate && predicate_op, Consumer && out)
96 {
97  if (typeid(E) == e.type() && typeid(E) == op.exectype.type()) {
98  auto & pipe_exec = op.exectype;
99  auto & actual_exec = *pipe_exec. template execution_ptr<E>();
100  auto transformed_pipe = transform_pipeline(actual_exec, std::forward<std::tuple<MoreTransformers...>>(op.stages));
101  repeat_until(*e.execution_ptr<E>(),
102  std::forward<Generator>(in),
103  std::forward<pipeline_info<E,MoreTransformers...> >(transformed_pipe), std::forward<Predicate>(predicate_op),
104  std::forward<Consumer>(out));
105  }
106  else {
107  repeat_until_multi_impl<O...>(e, std::forward<Generator>(in),
108  std::forward<pipeline_info<polymorphic_execution,MoreTransformers...> >(op), std::forward<Predicate>(predicate_op),
109  std::forward<Consumer>(out));
110  }
111 }
112 
113 template<typename Generator, typename Predicate, typename Consumer,
114  typename Operation>
116  Operation && op, Predicate && predicate_op, Consumer && out)
117 {
118 }
119 
120 template <typename E, typename ... O,
121  typename Generator, typename Predicate, typename Consumer,
122  typename Operation,
123  internal::requires_execution_not_supported<E> = 0>
125  Operation && op, Predicate && predicate_op, Consumer && out)
126 {
127  repeat_until_multi_impl<O...>(e, std::forward<Generator>(in),
128  std::forward<Operation>(op), std::forward<Predicate>(predicate_op),
129  std::forward<Consumer>(out));
130 }
131 
132 template <typename E, typename ... O,
133  typename Generator, typename Predicate, typename Consumer,
134  typename Operation,
135  internal::requires_execution_supported<E> = 0>
136 void repeat_until_multi_impl(polymorphic_execution & e, Generator && in,
137  Operation && op, Predicate && predicate_op, Consumer && out)
138 {
139  if (typeid(E) == e.type()) {
140  repeat_until(*e.execution_ptr<E>(),
141  std::forward<Generator>(in),
142  std::forward<Operation>(op), std::forward<Predicate>(predicate_op),
143  std::forward<Consumer>(out));
144  }
145  else {
146  repeat_until_multi_impl<O...>(e, std::forward<Generator>(in),
147  std::forward<Operation>(op), std::forward<Predicate>(predicate_op),
148  std::forward<Consumer>(out));
149  }
150 }
151 
174 template <typename Generator, typename Predicate, typename Consumer,
175  typename Transformer>
177  Generator && generate_op,
179  Predicate && predicate_op, Consumer && consume_op)
180 {
184  >(ex, std::forward<Generator>(generate_op),
185  std::forward<farm_info<polymorphic_execution,Transformer> >(farm_obj),
186  std::forward<Predicate>(predicate_op),
187  std::forward<Consumer>(consume_op));
188 }
189 
203 template <typename Generator, typename Predicate, typename Consumer,
204  typename ... Transformers>
205 void repeat_until(polymorphic_execution & ex, Generator && generate_op,
207  Predicate && predicate_op, Consumer && consume_op)
208 {
212  >(ex, std::forward<Generator>(generate_op),
214  std::forward<Predicate>(predicate_op),
215  std::forward<Consumer>(consume_op));
216 }
217 
231 template <typename Generator, typename Transformer, typename Predicate, typename Consumer>
233  Generator && generate_op,
234  Transformer && transform_op, Predicate && predicate_op,
235  Consumer && consume_op)
236 {
240  >(ex, std::forward<Generator>(generate_op), std::forward<Transformer>(transform_op),
241  std::forward<Predicate>(predicate_op), std::forward<Consumer>(consume_op));
242 }
243 
244 } // end namespace grppi
245 
246 #endif
Definition: callable_traits.h:24
void repeat_until_multi_impl(polymorphic_execution &e, Generator &&in, farm_info< polymorphic_execution, Transformer > &&op, Predicate &&predicate_op, Consumer &&out)
Definition: poly/stream_iteration.h:31
Definition: patterns.h:29
void repeat_until(parallel_execution_native &ex, Generator &&generate_op, pipeline_info< parallel_execution_native, MoreTransformers... > &&pipe, Predicate predicate_op, Consumer consume_op)
Invoke Stream iteration pattern on a data stream with native parallel execution with a generator...
Definition: native/stream_iteration.h:55
pipeline_info< Execution, Transformer, MoreTransformers... > transform_pipeline(Execution &ex, std::tuple< Transformer, MoreTransformers... > &&transform_ops)
Definition: poly/pipeline.h:33
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
E * execution_ptr()
Get the execution pointer for a given type.
Definition: polymorphic_execution.h:91
Definition: patterns.h:51
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