skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
hpp-execution
This page is read only. You can view the source, but not change it.
# <execution> **[<execution>](https://en.cppreference.com/w/cpp/header/execution)** provides execution policies for parallel algorithms introduced in C++17: `std::execution::seq` (sequential), `std::execution::par` (parallel), `std::execution::par_unseq` (parallel, unsequenced), `std::execution::unseq` (unsequenced, C++20). These policies are passed to algorithms like `std::sort`, `std::for_each`, and `std::transform` to request parallelization. The standard library or compiler runtime chooses how many threads to use. This example sorts a vector using the `std::execution::par` policy to enable parallel sorting across multiple threads. ```cpp // compile: g++ -std=c++17 -pthread -O3 -o executionexample executionexample.cpp // run: ./executionexample // description: parallel sort using execution policy #include <execution> #include <algorithm> #include <vector> #include <iostream> #include <random> int main() { std::vector<int> v(1000); std::iota(v.begin(), v.end(), 0); std::shuffle(v.begin(), v.end(), std::mt19937{}); std::sort(std::execution::par, v.begin(), v.end()); std::cout << "first 5: "; for (int i = 0; i < 5; ++i) std::cout << v[i] << " "; std::cout << "\n"; return 0; } ```
Page Tools
Show pagesource
Backlinks
Back to top