GrPPI  0.3.1
Generic and Reusable Parallel Pattern Interface
patterns.h
Go to the documentation of this file.
1 /*
2 * @version GrPPI v0.2
3 * @copyright Copyright (C) 2017 Universidad Carlos III de Madrid. All rights reserved.
4 * @license GNU/GPL, see LICENSE.txt
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You have received a copy of the GNU General Public License in LICENSE.txt
16 * also available in <http://www.gnu.org/licenses/gpl.html>.
17 *
18 * See COPYRIGHT.txt for copyright notices and details.
19 */
20 
21 #ifndef GRPPI_COMMON_PATTERNS_H
22 #define GRPPI_COMMON_PATTERNS_H
23 
24 #include <tuple>
25 #include <type_traits>
26 
27 #include "callable_traits.h"
28 #include "farm_pattern.h"
29 #include "filter_pattern.h"
30 #include "pipeline_pattern.h"
31 #include "reduce_pattern.h"
32 #include "iteration_pattern.h"
33 #include "context.h"
34 
35 namespace grppi{
36 
37 template <typename E,typename Stage, typename ... Stages>
39  public:
40  E & exectype;
41  std::tuple<Stage , Stages ...> stages;
42  pipeline_info(E &p, Stage s, Stages ... sts) : exectype{p}, stages{std::make_tuple(s, sts...)} {}
43  pipeline_info(E &p, std::tuple<Stage,Stages ...> st) : exectype{p} , stages{st} {}
44 };
45 
46 template <typename E,class Combiner, typename Identity>
48 {
49  public:
50  Combiner combine_op;
52  int offset;
53  Identity identity;
54  E & exectype;
55  reduction_info(E &s,int ws, int off, Identity iden, Combiner comb) :
56  exectype{s}, window_size{ws}, offset{off}, identity{iden}, combine_op{comb} {}
57 };
58 
59 template <typename E,class Operation>
60 class farm_info
61 {
62  public:
63  Operation task;
64  E & exectype;
65  int farmtype;
66  farm_info(E &s,Operation f) : task{f}, exectype{s}, farmtype{} {};
67 };
68 
69 template <typename E,class Operation>
71 {
72  public:
73  Operation task;
74  E & exectype;
76  filter_info(E &s,Operation f) : task{f}, exectype{s}, filtertype{} {};
77 };
78 
79 template <typename T>
80 constexpr bool is_no_pattern =
81  !is_farm<T> &&
82  !is_filter<T> &&
83  !is_pipeline<T> &&
84  !is_reduce<T> &&
85  !is_iteration<T>&&
86  !is_context<T>;
87 
88 template <typename T>
89 constexpr bool is_pattern = !is_no_pattern<T>;
90 
91 template <typename T>
92 using requires_no_pattern = std::enable_if_t<is_no_pattern<T>,int>;
93 
94 template <typename T>
95 using requires_pattern = std::enable_if_t<is_pattern<T>, int>;
96 
101 template <typename return_type, typename ... Ts>
103  using type = return_type;
104 };
105 
109 template <typename Input, typename Transformer>
110 using result_type = typename std::result_of<Transformer(Input)>::type;
111 
115 template <typename Input, typename Transformer>
116 struct stage_return_type<Input, Transformer> {
118 };
119 
124 template <typename Input, typename Transformer, typename ... Other>
125 struct stage_return_type<Input, Transformer, Other ...> {
127 };
128 
129 } // end namespace grppi
130 
131 #endif
Definition: callable_traits.h:26
Operation task
Definition: patterns.h:63
Definition: patterns.h:70
E & exectype
Definition: patterns.h:64
Definition: patterns.h:47
Identity identity
Definition: patterns.h:53
Combiner combine_op
Definition: patterns.h:50
Definition: patterns.h:38
std::enable_if_t< is_pattern< T >, int > requires_pattern
Definition: patterns.h:95
farm_info(E &s, Operation f)
Definition: patterns.h:66
E & exectype
Definition: patterns.h:40
Determines the return type after appliying a list of transformers (stages) on a input type...
Definition: patterns.h:102
std::tuple< Stage, Stages... > stages
Definition: patterns.h:41
E & exectype
Definition: patterns.h:74
std::enable_if_t< is_no_pattern< T >, int > requires_no_pattern
Definition: patterns.h:92
constexpr bool is_pattern
Definition: patterns.h:89
int farmtype
Definition: patterns.h:65
return_type type
Definition: patterns.h:103
constexpr bool is_no_pattern
Definition: patterns.h:80
Definition: patterns.h:60
int filtertype
Definition: patterns.h:75
typename stage_return_type< result_type< Input, Transformer >>::type type
Definition: patterns.h:117
pipeline_info(E &p, Stage s, Stages...sts)
Definition: patterns.h:42
typename std::result_of< Transformer(Input)>::type result_type
Determines the return type of appliying a function on a input type.
Definition: patterns.h:110
typename stage_return_type< result_type< Input, Transformer >, Other... >::type type
Definition: patterns.h:126
int window_size
Definition: patterns.h:51
filter_info(E &s, Operation f)
Definition: patterns.h:76
pipeline_info(E &p, std::tuple< Stage, Stages... > st)
Definition: patterns.h:43
Operation task
Definition: patterns.h:73
E & exectype
Definition: patterns.h:54
int offset
Definition: patterns.h:52
reduction_info(E &s, int ws, int off, Identity iden, Combiner comb)
Definition: patterns.h:55