29 #ifndef PIRANHA_DETAIL_PARALLEL_VECTOR_TRANSFORM_HPP 30 #define PIRANHA_DETAIL_PARALLEL_VECTOR_TRANSFORM_HPP 36 #include <piranha/config.hpp> 38 #include <piranha/thread_pool.hpp> 46 template <
typename T,
typename U,
typename Op>
47 inline void parallel_vector_transform(
unsigned n_threads,
const std::vector<T> &ic, std::vector<U> &oc, Op op)
49 if (unlikely(n_threads == 0u)) {
50 piranha_throw(std::invalid_argument,
"invalid number of threads");
52 if (unlikely(ic.size() != oc.size())) {
53 piranha_throw(std::invalid_argument,
"mismatched vector sizes");
55 if (n_threads == 1u) {
56 std::transform(ic.begin(), ic.end(), oc.begin(), op);
59 const auto block_size = ic.size() / n_threads;
60 auto local_transform = [&op](T
const *b, T
const *e, U *o) { std::transform(b, e, o, op); };
61 future_list<decltype(local_transform(ic.data(), ic.data(), oc.data()))> ff_list;
63 for (
unsigned i = 0u; i < n_threads; ++i) {
64 auto b = ic.data() + i * block_size;
65 auto e = (i == n_threads - 1u) ? (ic.data() + ic.size()) : (ic.data() + (i + 1u) * block_size);
66 auto o = oc.data() + i * block_size;
static enqueue_t< F &&, Args &&... > enqueue(unsigned n, F &&f, Args &&... args)
Enqueue task.
#define piranha_throw(exception_type,...)
Exception-throwing macro.