Published May 3, 2021
| Version v3.2.0
Software
Open
A C++17 Thread Pool for High-Performance Scientific Computing
Creators
Description
BS_thread_pool.hpp
:- Main
BS::thread_pool
class:- Added a new member function,
push_loop()
, which does the same thing asparallelize_loop()
, except that it does not return aBS::multi_future
with the futures for each block. Just likepush_task()
vs.submit()
, this avoids the overhead of creating the futures, but the user must usewait_for_tasks()
or some other method to ensure that the loop finishes executing, otherwise bad things will happen. push_task()
andsubmit()
now utilize perfect forwarding in order to support more types of tasks - in particular member functions, which in previous versions could not be submitted unless wrapped in a lambda. To submit a member function, use the syntaxsubmit(&class::function, &object, args)
. More information can be found inREADME.md
. See #9.push_loop()
andparallelize_loop()
now have overloads where the first argument (the first index in the loop) is omitted, in which case it is assumed to be 0. This is for convenience, as the case where the first index is 0 is very common.
- Added a new member function,
- Helper classes:
BS::synced_stream
now utilizes perfect forwarding in the member functionsprint()
andprintln()
.- Previously, it was impossible to pass the flushing manipulators
std::endl
andstd::flush
toprint()
andprintln()
, since the compiler could not figure out which template specializations to use. The new objectsBS::endl
andBS::flush
are explicit casts of these manipulators, whose sole purpose is to enable passing them toprint()
andprintln()
. BS::multi_future::get()
now rethrows exceptions generated by the futures, even if the futures returnvoid
. See #62.- Added a new helper class,
BS::blocks
, which is used byparallelize_loop()
andpush_loop()
to divide a range into blocks. This class is not documented inREADME.md
, as it most likely will not be of interest to most users, but it is still publicly available, in case you want to parallelize something manually but still benefit from the built-in algorithm for splitting a range into blocks.
- Main
BS_thread_pool_test.cpp
:- Added plenty of new tests for the new features described above.
- Fixed a bug in
count_unique_threads()
that caused it to get stuck on certain systems. dual_println()
now also flushes the stream usingBS::endl
, so that if the test gets stuck, the log file will still contain everything up to that point. (Note: It is a common misconception thatstd::endl
and'\n'
are interchangeable.std::endl
not only prints a newline character, it also flushes the stream, which is not always desirable, as it may reduce performance.)- The performance test has been modified as follows:
- Instead of generating random vectors using
std::mersenne_twister_engine
, which proved to be inconsistent across different compilers and systems, the test now generates each element via an arbitrarily-chosen numerical operation. In my testing, this provided much more consistent results. - Instead of using a hard-coded vector size, a suitable vector size is now determined dynamically at runtime.
- Instead of using
parallelize_loop()
, the test now uses the newpush_loop()
function to squeeze out a bit more performance. - Instead of setting the test parameters to achieve a fixed single-threaded mean execution time of 300 ms, the test now aims to achieve a fixed multi-threaded mean execution time of 50 ms when the number of blocks is equal to the number of threads. This allows for more reliable results on very fast CPUs with a very large number of threads, where the mean execution time when using all the threads could previously be below a statistically significant value.
- The number of vectors is now restricted to be a multiple of the number of threads, so that the blocks are always all of the same size.
- Instead of generating random vectors using
README.md
:- Added instructions and examples for the new features described above.
- Rewrote the documentation for
parallelize_loop()
to make it clearer.
Notes
Files
bshoshany/thread-pool-v3.2.0.zip
Files
(48.5 kB)
Name | Size | Download all |
---|---|---|
md5:eaa30920f93f902561c03ba2d7684589
|
48.5 kB | Preview Download |
Additional details
Related works
- Is supplement to
- https://github.com/bshoshany/thread-pool/tree/v3.2.0 (URL)