16 #ifndef GRPPI_DYN_DYNAMIC_EXECUTION_H
17 #define GRPPI_DYN_DYNAMIC_EXECUTION_H
19 #include "../seq/sequential_execution.h"
20 #include "../native/parallel_execution_native.h"
21 #include "../tbb/parallel_execution_tbb.h"
22 #include "../omp/parallel_execution_omp.h"
23 #include "../ff/parallel_execution_ff.h"
55 template <
typename ... InputIterators,
typename OutputIterator,
57 void map(std::tuple<InputIterators...> firsts,
58 OutputIterator first_out, std::size_t sequence_size,
59 Transformer && transform_op)
const;
74 template <
typename InputIterator,
typename Identity,
typename Combiner>
75 auto reduce(InputIterator first, std::size_t sequence_size,
77 Combiner && combine_op)
const;
93 template <
typename ... InputIterators,
typename Identity,
94 typename Transformer,
typename Combiner>
95 auto map_reduce(std::tuple<InputIterators...> firsts,
96 std::size_t sequence_size,
98 Transformer && transform_op, Combiner && combine_op)
const;
116 template <
typename ... InputIterators,
typename OutputIterator,
117 typename StencilTransformer,
typename Neighbourhood>
118 void stencil(std::tuple<InputIterators...> firsts, OutputIterator first_out,
119 std::size_t sequence_size,
120 StencilTransformer && transform_op,
121 Neighbourhood && neighbour_op)
const;
135 template <
typename Input,
typename Div
ider,
typename Solver,
typename Combiner>
136 [[deprecated(
"Use new interface with predicate argument")]]
138 Divider && divide_op,
140 Combiner && combine_op)
const;
157 template <
typename Input,
typename Div
ider,
typename Predicate,
typename Solver,
typename Combiner>
159 Divider && divide_op,
160 Predicate && predicate_op,
162 Combiner && combine_op)
const;
172 template <
typename Generator,
typename ... Transformers>
173 void pipeline(Generator && generate_op,
174 Transformers && ... transform_ops)
const;
178 class execution_base {
180 virtual ~execution_base() {};
183 template <
typename E>
184 class execution :
public execution_base {
186 execution(
const E & e) : ex_{e} {}
187 virtual ~execution() =
default;
193 std::unique_ptr<execution_base> execution_;
248 #define GRPPI_TRY_PATTERN(E,PATTERN,...)\
250 if (supports_##PATTERN<E>()) {\
251 auto * ex = dynamic_cast<execution<E>*>(execution_.get());\
253 return ex->ex_.PATTERN(__VA_ARGS__);\
258 #define GRPPI_PATTERN_NOT_IMPLEMENTED(PATTERN,...)\
259 throw std::runtime_error{"Pattern " #PATTERN " not implemented"};
262 #define GRPPI_TRY_PATTERN_OMP(PATTERN,...) \
263 GRPPI_TRY_PATTERN(parallel_execution_omp,PATTERN,__VA_ARGS__)
265 #define GRPPI_TRY_PATTERN_OMP(PATTERN,...)
269 #define GRPPI_TRY_PATTERN_TBB(PATTERN,...) \
270 GRPPI_TRY_PATTERN(parallel_execution_tbb,PATTERN,__VA_ARGS__)
272 #define GRPPI_TRY_PATTERN_TBB(PATTERN,...)
276 #define GRPPI_TRY_PATTERN_FF(PATTERN,...) \
277 GRPPI_TRY_PATTERN(parallel_execution_ff,PATTERN,__VA_ARGS__)
279 #define GRPPI_TRY_PATTERN_FF(PATTERN,...)
282 #define GRPPI_TRY_PATTERN_ALL(...) \
283 GRPPI_TRY_PATTERN(sequential_execution, __VA_ARGS__) \
284 GRPPI_TRY_PATTERN(parallel_execution_native, __VA_ARGS__) \
285 GRPPI_TRY_PATTERN_OMP(__VA_ARGS__) \
286 GRPPI_TRY_PATTERN_TBB(__VA_ARGS__) \
287 GRPPI_TRY_PATTERN_FF(__VA_ARGS__) \
288 GRPPI_PATTERN_NOT_IMPLEMENTED(__VA_ARGS__)\
290 #define GRPPI_TRY_PATTERN_ALL_NOFF(...) \
291 GRPPI_TRY_PATTERN(sequential_execution, __VA_ARGS__) \
292 GRPPI_TRY_PATTERN(parallel_execution_native, __VA_ARGS__) \
293 GRPPI_TRY_PATTERN_OMP(__VA_ARGS__) \
294 GRPPI_TRY_PATTERN_TBB(__VA_ARGS__) \
295 GRPPI_PATTERN_NOT_IMPLEMENTED(__VA_ARGS__)\
297 template <
typename ... InputIterators,
typename OutputIterator,
298 typename Transformer>
300 std::tuple<InputIterators...> firsts,
301 OutputIterator first_out,
302 std::size_t sequence_size,
303 Transformer && transform_op)
const
306 std::forward<Transformer>(transform_op));
309 template <
typename InputIterator,
typename Identity,
typename Combiner>
311 Identity && identity,
312 Combiner && combine_op)
const
315 std::forward<Identity>(identity), std::forward<Combiner>(combine_op));
318 template <
typename ... InputIterators,
typename Identity,
319 typename Transformer,
typename Combiner>
321 std::tuple<InputIterators...> firsts,
322 std::size_t sequence_size,
323 Identity && identity,
324 Transformer && transform_op,
325 Combiner && combine_op)
const
328 std::forward<Identity>(identity),
329 std::forward<Transformer>(transform_op),
330 std::forward<Combiner>(combine_op));
333 template <
typename ... InputIterators,
typename OutputIterator,
334 typename StencilTransformer,
typename Neighbourhood>
336 std::tuple<InputIterators...> firsts,
337 OutputIterator first_out,
338 std::size_t sequence_size,
339 StencilTransformer && transform_op,
340 Neighbourhood && neighbour_op)
const
343 std::forward<StencilTransformer>(transform_op),
344 std::forward<Neighbourhood>(neighbour_op));
347 template <
typename Input,
typename Div
ider,
typename Solver,
typename Combiner>
350 Divider && divide_op,
352 Combiner && combine_op)
const
355 std::forward<Divider>(divide_op),
356 std::forward<Solver>(solve_op),
357 std::forward<Combiner>(combine_op));
361 template <
typename Input,
typename Div
ider,
typename Predicate,
typename Solver,
typename Combiner>
364 Divider && divide_op,
365 Predicate && predicate_op,
367 Combiner && combine_op)
const
370 std::forward<Divider>(divide_op),
371 std::forward<Predicate>(predicate_op),
372 std::forward<Solver>(solve_op),
373 std::forward<Combiner>(combine_op));
376 template <
typename Generator,
typename ... Transformers>
378 Generator && generate_op,
379 Transformers && ... transform_ops)
const
382 std::forward<Transformers>(transform_ops)...);
385 #undef GRPPI_TRY_PATTERN
386 #undef GRPPI_TRY_PATTERN_OMP
387 #undef GRPPI_TRY_PATTERN_TBB
388 #undef GRPPI_TRY_PATTERN_ALL
389 #undef GRPPI_TRY_PATTERN_ALL_NOFF
Definition: dynamic_execution.h:29
auto map_reduce(std::tuple< InputIterators... > firsts, std::size_t sequence_size, Identity &&identity, Transformer &&transform_op, Combiner &&combine_op) const
Applies a map/reduce operation to a sequence of data items.
Definition: dynamic_execution.h:320
auto divide_conquer(Input &&input, Divider &÷_op, Solver &&solve_op, Combiner &&combine_op) const
Invoke md_divide-conquer.
Definition: dynamic_execution.h:348
void stencil(std::tuple< InputIterators... > firsts, OutputIterator first_out, std::size_t sequence_size, StencilTransformer &&transform_op, Neighbourhood &&neighbour_op) const
Applies a stencil to multiple sequences leaving the result in another sequence.
Definition: dynamic_execution.h:335
void pipeline(Generator &&generate_op, Transformers &&... transform_ops) const
Invoke Pipeline pattern.
Definition: dynamic_execution.h:377
dynamic_execution() noexcept
Definition: dynamic_execution.h:32
auto reduce(InputIterator first, std::size_t sequence_size, Identity &&identity, Combiner &&combine_op) const
Applies a reduction to a sequence of data items.
Definition: dynamic_execution.h:310
void map(std::tuple< InputIterators... > firsts, OutputIterator first_out, std::size_t sequence_size, Transformer &&transform_op) const
Applies a transformation to multiple sequences leaving the result in another sequence.
Definition: dynamic_execution.h:299
dynamic_execution(const E &e)
Definition: dynamic_execution.h:37
bool has_execution() const
Definition: dynamic_execution.h:39
#define GRPPI_TRY_PATTERN_ALL(...)
Definition: dynamic_execution.h:282
#define GRPPI_TRY_PATTERN_ALL_NOFF(...)
Definition: dynamic_execution.h:290
Definition: callable_traits.h:21
constexpr bool supports_stencil< dynamic_execution >()
Determines if an execution policy supports the stencil pattern.
Definition: dynamic_execution.h:230
constexpr bool supports_map_reduce< dynamic_execution >()
Determines if an execution policy supports the map-reduce pattern.
Definition: dynamic_execution.h:223
constexpr bool supports_pipeline< dynamic_execution >()
Determines if an execution policy supports the pipeline pattern.
Definition: dynamic_execution.h:244
constexpr bool supports_reduce< dynamic_execution >()
Determines if an execution policy supports the reduce pattern.
Definition: dynamic_execution.h:216
constexpr bool supports_divide_conquer< dynamic_execution >()
Determines if an execution policy supports the divide/conquer pattern.
Definition: dynamic_execution.h:237
constexpr bool is_supported< dynamic_execution >()
Determines if an execution policy is supported in the current compilation.
Definition: dynamic_execution.h:202
constexpr bool supports_map< dynamic_execution >()
Determines if an execution policy supports the map pattern.
Definition: dynamic_execution.h:209