GrPPI  1.0
Generic and Reusable Parallel Pattern Interface
patterns.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Universidad Carlos III de Madrid
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef GRPPI_COMMON_PATTERNS_H
17 #define GRPPI_COMMON_PATTERNS_H
18 
19 #include <tuple>
20 #include <type_traits>
21 
22 #include "callable_traits.h"
23 #include "farm_pattern.h"
24 #include "filter_pattern.h"
25 #include "pipeline_pattern.h"
26 #include "reduce_pattern.h"
27 #include "iteration_pattern.h"
28 #include "context.h"
29 
30 namespace grppi{
31 
32 template <typename E,typename Stage, typename ... Stages>
34  public:
35  E & exectype;
36  std::tuple<Stage , Stages ...> stages;
37  pipeline_info(E &p, Stage s, Stages ... sts) : exectype{p}, stages{std::make_tuple(s, sts...)} {}
38  pipeline_info(E &p, std::tuple<Stage,Stages ...> st) : exectype{p} , stages{st} {}
39 };
40 
41 template <typename E,class Combiner, typename Identity>
43 {
44  public:
45  Combiner combine_op;
47  int offset;
48  Identity identity;
49  E & exectype;
50  reduction_info(E &s,int ws, int off, Identity iden, Combiner comb) :
51  exectype{s}, window_size{ws}, offset{off}, identity{iden}, combine_op{comb} {}
52 };
53 
54 template <typename E,class Operation>
55 class farm_info
56 {
57  public:
58  Operation task;
59  E & exectype;
60  int farmtype;
61  farm_info(E &s,Operation f) : task{f}, exectype{s}, farmtype{} {};
62 };
63 
64 template <typename E,class Operation>
66 {
67  public:
68  Operation task;
69  E & exectype;
71  filter_info(E &s,Operation f) : task{f}, exectype{s}, filtertype{} {};
72 };
73 
74 template <typename T>
75 constexpr bool is_no_pattern =
76  !is_farm<T> &&
77  !is_filter<T> &&
78  !is_pipeline<T> &&
79  !is_reduce<T> &&
80  !is_iteration<T>&&
81  !is_context<T>;
82 
83 template <typename T>
84 constexpr bool is_pattern = !is_no_pattern<T>;
85 
86 template <typename T>
87 using requires_no_pattern = std::enable_if_t<is_no_pattern<T>,int>;
88 
89 template <typename T>
90 using requires_pattern = std::enable_if_t<is_pattern<T>, int>;
91 
96 template <typename return_type, typename ... Ts>
98  using type = return_type;
99 };
100 
104 template <typename Input, typename Transformer>
105 using result_type = typename std::result_of<Transformer(Input)>::type;
106 
110 template <typename Input, typename Transformer>
111 struct stage_return_type<Input, Transformer> {
113 };
114 
119 template <typename Input, typename Transformer, typename ... Other>
120 struct stage_return_type<Input, Transformer, Other ...> {
122 };
123 
124 } // end namespace grppi
125 
126 #endif
Definition: patterns.h:56
int farmtype
Definition: patterns.h:60
Operation task
Definition: patterns.h:58
farm_info(E &s, Operation f)
Definition: patterns.h:61
E & exectype
Definition: patterns.h:59
Definition: patterns.h:66
filter_info(E &s, Operation f)
Definition: patterns.h:71
Operation task
Definition: patterns.h:68
int filtertype
Definition: patterns.h:70
E & exectype
Definition: patterns.h:69
Definition: patterns.h:33
std::tuple< Stage, Stages ... > stages
Definition: patterns.h:36
pipeline_info(E &p, std::tuple< Stage, Stages ... > st)
Definition: patterns.h:38
E & exectype
Definition: patterns.h:35
pipeline_info(E &p, Stage s, Stages ... sts)
Definition: patterns.h:37
Definition: patterns.h:43
Combiner combine_op
Definition: patterns.h:45
Identity identity
Definition: patterns.h:48
int window_size
Definition: patterns.h:46
E & exectype
Definition: patterns.h:49
int offset
Definition: patterns.h:47
reduction_info(E &s, int ws, int off, Identity iden, Combiner comb)
Definition: patterns.h:50
Definition: callable_traits.h:21
constexpr bool is_no_pattern
Definition: patterns.h:75
std::enable_if_t< is_pattern< T >, int > requires_pattern
Definition: patterns.h:90
typename std::result_of< Transformer(Input)>::type result_type
Determines the return type of applying a function on a input type.
Definition: patterns.h:105
constexpr bool is_pattern
Definition: patterns.h:84
std::enable_if_t< is_no_pattern< T >, int > requires_no_pattern
Definition: patterns.h:87
typename stage_return_type< result_type< Input, Transformer >, Other... >::type type
Definition: patterns.h:121
typename stage_return_type< result_type< Input, Transformer > >::type type
Definition: patterns.h:112
Determines the return type after applying a list of transformers (stages) on a input type.
Definition: patterns.h:97
return_type type
Definition: patterns.h:98