21 #ifndef GRPPI_NATIVE_PARALLEL_EXECUTION_NATIVE_H 22 #define GRPPI_NATIVE_PARALLEL_EXECUTION_NATIVE_H 24 #include "../common/mpmc_queue.h" 31 #include <type_traits> 71 mutable std::atomic_flag lock_ = ATOMIC_FLAG_INIT;
72 std::vector<std::thread::id> ids_;
78 while (lock_.test_and_set(memory_order_acquire)) {}
79 auto this_id = this_thread::get_id();
80 ids_.push_back(this_id);
81 lock_.clear(memory_order_release);
87 while (lock_.test_and_set(memory_order_acquire)) {}
88 auto this_id = this_thread::get_id();
89 auto current = find(begin(ids_), end(ids_), this_id);
91 lock_.clear(memory_order_release);
97 while (lock_.test_and_set(memory_order_acquire)) {}
98 auto this_id = this_thread::get_id();
99 auto current = find(begin(ids_), end(ids_), this_id);
100 auto index = distance(begin(ids_), current);
101 lock_.clear(memory_order_release);
117 : registry_{registry}
124 registry_.deregister_thread();
151 static_cast<int>(2 * std::thread::hardware_concurrency()),
164 concurrency_degree_{concurrency_degree},
167 pool.initialise(concurrency_degree_);
208 return thread_registry_.current_index();
224 template <
typename T>
226 return {queue_size_, queue_mode_};
240 int concurrency_degree_;
243 constexpr
static int default_queue_size = 100;
244 int queue_size_ = default_queue_size;
253 template <
typename E>
255 return std::is_same<E, parallel_execution_native>::value;
262 template <
typename E>
Definition: callable_traits.h:24
void set_concurrency_degree(int degree) noexcept
Set number of grppi threads.
Definition: parallel_execution_native.h:173
constexpr bool is_supported< parallel_execution_native >()
Specialization stating that parallel_execution_native is supported.
Definition: parallel_execution_native.h:269
native_thread_manager(thread_registry ®istry)
Saves a reference to the registry and registers current thread.
Definition: parallel_execution_native.h:116
constexpr bool is_supported()
Metafunction that determines if type E is supported in the current build.
void enable_ordering() noexcept
Enable ordering.
Definition: parallel_execution_native.h:183
int concurrency_degree() const noexcept
Get number of grppi trheads.
Definition: parallel_execution_native.h:178
void set_queue_attributes(int size, queue_mode mode) noexcept
Sets the attributes for the queues built through make_queue<T>()
Definition: parallel_execution_native.h:214
thread_pool pool
Thread pool for lanching workers.
Definition: parallel_execution_native.h:235
queue_mode
Definition: mpmc_queue.h:35
void deregister_thread() noexcept
Removes current thread id from the registry.
Definition: parallel_execution_native.h:84
Native parallel execution policy. This policy uses ISO C++ threads as implementation building block a...
Definition: parallel_execution_native.h:136
thread_registry() noexcept=default
Definition: mpmc_queue.h:38
parallel_execution_native() noexcept
Default construct a native parallel execution policy.
Definition: parallel_execution_native.h:149
~native_thread_manager()
Deregisters current thread from the registry.
Definition: parallel_execution_native.h:123
constexpr bool is_parallel_execution_native()
Metafunction that determines if type E is parallel_execution_native.
Definition: parallel_execution_native.h:254
void register_thread() noexcept
Adds the current thread id in the registry.
Definition: parallel_execution_native.h:75
native_thread_manager thread_manager()
Get a manager object for registration/deregistration in the thread index table for current thread...
Definition: parallel_execution_native.h:199
int current_index() const noexcept
Integer index for current thread.
Definition: parallel_execution_native.h:94
parallel_execution_native(int concurrency_degree, bool ordering=true) noexcept
Constructs a native parallel execution policy.
Definition: parallel_execution_native.h:163
Thread index table to provide portable natural thread indices.
Definition: parallel_execution_native.h:49
void disable_ordering() noexcept
Disable ordering.
Definition: parallel_execution_native.h:188
RAII class to manage registration/deregistration pairs. This class allows to manage automatic deregis...
Definition: parallel_execution_native.h:111
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_native.h:225
int get_thread_id() const noexcept
Get index of current thread in the thread table.
Definition: parallel_execution_native.h:207
bool is_ordered() const noexcept
Is execution ordered.
Definition: parallel_execution_native.h:193