D
D
Daniel Demidko2019-12-31 12:01:58
C++ / C#
Daniel Demidko, 2019-12-31 12:01:58

How to execute one function for all vector elements at the same time?

Yes vector<T> vec, function . I want to execute the function f for each element in vec, and store all the results in ; This can be done with a loopbool f(T)
vector<bool> res

for(auto &i: vec)
{
    res.push_back(f(i));
}

But I want to parallelize the execution of the function f for each element using C++ threads/future
The function f is pure.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Moseychuk, 2019-12-31
@DanielDemidko

https://en.cppreference.com/w/cpp/experimental/par...
https://github.com/intel/parallelstl/blob/master/R...
OpenMP
Naturally, there is nothing suitable out of the box.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question