GrPPI  0.2
Generic and Reusable Parallel Pattern Interface
parallel_execution_tbb.h
Go to the documentation of this file.
1 
21 #ifndef GRPPI_TBB_PARALLEL_EXECUTION_TBB_H
22 #define GRPPI_TBB_PARALLEL_EXECUTION_TBB_H
23 
24 #ifdef GRPPI_TBB
25 
26 #include "../common/mpmc_queue.h"
27 
28 #include <type_traits>
29 
30 namespace grppi {
31 
38 public:
39 
49  parallel_execution_tbb{default_concurrency_degree}
50  {}
51 
60  parallel_execution_tbb(int concurrency_degree, bool order = true) noexcept :
61  concurrency_degree_{concurrency_degree},
62  ordering_{order}
63  {}
64 
68  void set_concurrency_degree(int degree) noexcept { concurrency_degree_ = degree; }
69 
73  int concurrency_degree() const noexcept { return concurrency_degree_; }
74 
78  void enable_ordering() noexcept { ordering_=true; }
79 
83  void disable_ordering() noexcept { ordering_=false; }
84 
88  bool is_ordered() const noexcept { return ordering_; }
89 
93  void set_queue_attributes(int size, queue_mode mode, int tokens) noexcept {
94  queue_size_ = size;
95  queue_mode_ = mode;
96  num_tokens_ = tokens;
97  }
98 
104  template <typename T>
106  return {queue_size_, queue_mode_};
107  }
108 
112  int tokens() const noexcept { return num_tokens_; }
113 
114 private:
115 
116  constexpr static int default_concurrency_degree = 4;
117  int concurrency_degree_ = default_concurrency_degree;
118 
119  bool ordering_ = true;
120 
121  constexpr static int default_queue_size = 100;
122  int queue_size_ = default_queue_size;
123 
124  constexpr static int default_num_tokens_ = 100;
125  int num_tokens_ = default_num_tokens_;
126 
127  queue_mode queue_mode_ = queue_mode::blocking;
128 };
129 
134 template <typename E>
135 constexpr bool is_parallel_execution_tbb() {
136  return std::is_same<E, parallel_execution_tbb>::value;
137 }
138 
143 template <typename E>
144 constexpr bool is_supported();
145 
150 template <>
152  return true;
153 }
154 
155 
156 } // end namespace grppi
157 
158 #else // GRPPI_TBB not defined
159 
160 namespace grppi {
161 
162 
165 struct parallel_execution_tbb {};
166 
172 template <typename E>
173 constexpr bool is_parallel_execution_tbb() {
174  return false;
175 }
176 
181 template <typename E>
182 constexpr bool is_supported();
183 
187 template <>
188 constexpr bool is_supported<parallel_execution_tbb>() {
189  return false;
190 }
191 
192 } // end namespace grppi
193 
194 #endif // GRPPI_TBB
195 
196 #endif
Definition: callable_traits.h:24
constexpr bool is_supported< parallel_execution_tbb >()
Specialization stating that parallel_execution_tbb is supported. This metafunction evaluates to false...
Definition: parallel_execution_tbb.h:151
constexpr bool is_supported()
Metafunction that determines if type E is supported in the current build.
int tokens() const noexcept
Definition: parallel_execution_tbb.h:112
void disable_ordering() noexcept
Disable ordering.
Definition: parallel_execution_tbb.h:83
constexpr bool is_parallel_execution_tbb()
Metafunction that determines if type E is parallel_execution_tbb.
Definition: parallel_execution_tbb.h:135
queue_mode
Definition: mpmc_queue.h:35
void set_concurrency_degree(int degree) noexcept
Set number of grppi threads.
Definition: parallel_execution_tbb.h:68
void set_queue_attributes(int size, queue_mode mode, int tokens) noexcept
Sets the attributes for the queues built through make_queue<T>()
Definition: parallel_execution_tbb.h:93
Definition: mpmc_queue.h:38
mpmc_queue< T > make_queue() const
Makes a communication queue for elements of type T. Constructs a queue using the attributes that can ...
Definition: parallel_execution_tbb.h:105
parallel_execution_tbb() noexcept
Default construct a TBB parallel execution policy.
Definition: parallel_execution_tbb.h:48
parallel_execution_tbb(int concurrency_degree, bool order=true) noexcept
Constructs a TBB parallel execution policy.
Definition: parallel_execution_tbb.h:60
TBB parallel execution policy.
Definition: parallel_execution_tbb.h:37
int concurrency_degree() const noexcept
Get number of grppi trheads.
Definition: parallel_execution_tbb.h:73
bool is_ordered() const noexcept
Is execution ordered.
Definition: parallel_execution_tbb.h:88
void enable_ordering() noexcept
Enable ordering.
Definition: parallel_execution_tbb.h:78