Execution Policies (Incomplete Draft)¶
Execution Policies¶
std::execution::seq
: sequential execution as if not specified at allstd::execution::par
: in parallel, multiple threads. Might fall back tostd::execution::seq
though.std::execution::par_unseq
: use vectorization. Might fall back tostd::execution::seq
though.
And Exceptions?¶
Parallel execution (
std::execution::par
andstd::execution::par_unseq
) does not like exceptionsProcess is terminated by default (
std::abort()
)⟶ You data should not throw on access
Examples¶
#include <random>
#include <algorithm>
#include <execution>
#include <iostream>
int main()
{
std::random_device rd;
std::vector<int> numbers;
for (int _=0; _<100000; _++)
numbers.push_back(rd());
std::sort(std::execution::par, numbers.begin(), numbers.end());
for (int elem: numbers)
std::cout << elem << std::endl;
return 0;
}
#include <random>
#include <algorithm>
#include <execution>
#include <iostream>
int main()
{
std::vector<int> numbers;
for (int i=0; i<1000; i++)
numbers.push_back(i);
std::for_each(
std::execution::par_unseq,
numbers.begin(), numbers.end(),
[](int elem){ std::cout << elem << std::endl; });
return 0;
}