17 #include <type_traits> 44 class execution_handler_parallel
63 execution_handler_parallel(
size_t const thread_count) : state{std::make_unique<internal_state>()}
65 auto * q = &(state->queue);
66 for (
size_t i = 0; i < thread_count; ++i)
68 state->thread_pool.emplace_back([q] ()
73 if (q->wait_pop(task) == contrib::queue_op_status::closed)
86 execution_handler_parallel(execution_handler_parallel
const &) =
delete;
87 execution_handler_parallel(execution_handler_parallel &&) =
default;
88 execution_handler_parallel & operator=(execution_handler_parallel
const &) =
delete;
89 execution_handler_parallel & operator=(execution_handler_parallel &&) =
default;
92 ~execution_handler_parallel()
102 template <
typename fn_type,
typename first_range_type,
typename second_range_type,
typename delegate_type>
110 void execute(fn_type && func,
112 first_range_type first_range,
113 second_range_type second_range,
114 delegate_type && delegate)
119 assert(state !=
nullptr);
121 task_type task = [=, first_range = std::move(first_range), second_range = std::move(second_range)] ()
123 delegate(func(idx, std::move(first_range), std::move(second_range)));
126 [[maybe_unused]] contrib::queue_op_status
status = state->queue.wait_push(std::move(task));
127 assert(status == contrib::queue_op_status::success);
133 assert(state !=
nullptr);
135 if (!state->is_waiting)
137 state->is_waiting =
true;
138 state->queue.close();
140 for (
auto & t : state->thread_pool)
150 struct internal_state
155 contrib::fixed_buffer_queue<task_type> queue{10000};
157 bool is_waiting{
false};
Provides seqan3::buffer_queue.
Specifies the requirements of a Range type that has constant time copy, move and assignment operators...
Specifies whether the given callable is invocable with the given arguments.
T hardware_concurrency(T... args)
Adaptations of concepts from the Ranges TS.
Provides seqan3::detail::reader_writer_manager.
Definition: aligned_sequence_concept.hpp:35