Jump to content

C++: Difference between revisions

376 bytes added ,  17 November 2021
No edit summary
Line 405: Line 405:
===Execution===
===Execution===
<code>#include <execution></code><br>
<code>#include <execution></code><br>
The execution header gives you tools for parallel execution.<br>
The execution header gives you tools for parallel execution (since C++17).<br>
See [https://en.cppreference.com/w/cpp/algorithm/execution_policy_tag_t execution_policy_tag].<br>
See [https://en.cppreference.com/w/cpp/algorithm/execution_policy_tag_t execution_policy_tag].<br>
[https://devblogs.microsoft.com/cppblog/using-c17-parallel-algorithms-for-better-performance/ C++17 Parallel Algorithms blog].<br>
[https://devblogs.microsoft.com/cppblog/using-c17-parallel-algorithms-for-better-performance/ C++17 Parallel Algorithms blog].<br>
[https://developer.nvidia.com/blog/accelerating-standard-c-with-gpus-using-stdpar/ Nvidia Accelerating Standard C++ with GPUs Using stdpar]<br>
;Parallel Sorting Example
;Parallel Sorting Example
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
std::sort(std::execution::par_unseq, sorted.begin(), sorted.end());
std::sort(std::execution::par_unseq, sorted.begin(), sorted.end());
</syntaxhighlight>
</syntaxhighlight>
* <code>std::execution::seq</code> sequential
* <code>std::execution::unseq</code> vectorized only (C++20)
* <code>std::execution::par</code> parallel
* <code>std::execution::par_unseq</code> parallel and vectorized


===Random===
===Random===