You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+59-56Lines changed: 59 additions & 56 deletions
Original file line number
Diff line number
Diff line change
@@ -5,50 +5,65 @@
5
5
6
6
Light, self-contained, thread pool-based implementation of [C++17 parallel standard library algorithms](https://en.cppreference.com/w/cpp/algorithm).
7
7
8
-
C++17 introduced parallel versions of many algorithms in the standard library.
9
-
These parallel versions accept an *Execution Policy* as their first argument.
10
-
Different policies allow the implementation to parallelize the algorithm in a different way,
11
-
such as using threads, vectorization, or even GPU.
8
+
C++17 introduced parallel overloads of standard library algorithms that accept an [*Execution Policy*](https://en.cppreference.com/w/cpp/algorithm/execution_policy_tag) as the first argument.
9
+
Policies specify limits on how the implementation may parallelize the algorithm, enabling methods like threads, vectorization, or even GPU.
12
10
Policies can be supplied by the compiler or by libraries like this one.
13
11
14
-
Unfortunately compiler support for the [standard policies](https://en.cppreference.com/w/cpp/algorithm/execution_policy_tag) varies.
15
-
PoolSTL is a *supplement* to fill in the support gaps, so we can use parallel algorithms now.
16
-
It is not meant as a full implementation; only the basics are expected to be covered. Use this if:
17
-
* you only need the basics, including no nested parallel calls.
18
-
* you must use a [compiler lacking native support](https://en.cppreference.com/w/cpp/compiler_support/17) (see "Parallel algorithms and execution policies").
19
-
* you cannot link against TBB for whatever reason.
20
-
* the [Parallel STL](https://www.intel.com/content/www/us/en/developer/articles/guide/get-started-with-parallel-stl.html) is too heavy.
* [`poolstl::iota_iter`](include/poolstl/iota_iter.hpp) - Iterate over integers. Same as iterating over output of [`std::iota`](https://en.cppreference.com/w/cpp/algorithm/iota) but without materializing anything. Iterator version of [`std::ranges::iota_view`](https://en.cppreference.com/w/cpp/ranges/iota_view).
46
61
47
62
## Usage
48
63
49
-
PoolSTL provides these execution policies:
64
+
PoolSTL provides:
50
65
* `poolstl::par`: Substitute for [`std::execution::par`](https://en.cppreference.com/w/cpp/algorithm/execution_policy_tag). Parallelized using a [thread pool](https://github.com/alugowski/task-thread-pool).
51
-
*`poolstl::seq`: Substitute for `std::execution::seq`. Simply calls the sequential (non-policy) overload.
66
+
* `poolstl::seq`: Substitute for `std::execution::seq`. Simply calls the regular (non-policy) overload.
52
67
* `poolstl::par_if()`: (C++17 only) choose parallel or sequential at runtime. See below.
53
68
54
69
In short, use `poolstl::par` to make your code parallel. Complete example:
@@ -58,7 +73,7 @@ In short, use `poolstl::par` to make your code parallel. Complete example:
58
73
59
74
int main() {
60
75
std::vector<int> v = {0, 1, 2, 3, 4, 5};
61
-
auto sum = std::reduce(poolstl::par, v.cbegin(), v.cend());
76
+
auto sum = std::reduce(poolstl::par, vec.cbegin(), vec.cend());
62
77
// ^^^^^^^^^^^^
63
78
// Add this to make your code parallel.
64
79
std::cout << "Sum=" << sum << std::endl;
@@ -68,15 +83,14 @@ int main() {
68
83
69
84
### Controlling Thread Pool Size with `par.on(pool)`
70
85
71
-
The thread pool used by `poolstl::par` is managed internally by poolSTL. It is started on first use.
72
-
86
+
The thread pool used by `poolstl::par` is managed internally by poolSTL. It is started on first use.
73
87
Use your own [thread pool](https://github.com/alugowski/task-thread-pool)
74
88
with `poolstl::par.on(pool)` for control over thread count, startup/shutdown, etc.:
Copy a single-file amalgamated `poolstl.hpp` from the [latest release](https://github.com/alugowski/poolSTL/releases) and into your project.
145
-
146
-
Note: Some compilers, including non-Apple Clang and GCC 8 and older, require the `-lpthread` linker flag to use C++11 threads.
148
+
Each [release](https://github.com/alugowski/poolSTL/releases/latest) publishes a single-file amalgamated `poolstl.hpp`. Simply copy this into your project.
149
+
**Note:** Some compilers (non-Apple Clang, GCC 8 and older) require `-lpthread` to use C++11 threads.
147
150
148
151
### CMake
149
152
@@ -205,7 +208,7 @@ reduce(std::execution::par)/real_time 3.38 ms
205
208
```
206
209
207
210
# poolSTL as `std::execution::par`
208
-
**USE AT YOUR OWN RISK!**
211
+
**USE AT YOUR OWN RISK! THIS IS A HACK!**
209
212
210
213
Two-line hack for missing compiler support. A no-op on compilers with support.
0 commit comments