|
rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
|
The backend that runs operations on the CPU of the host. More...
Classes | |
| class | cpu_device |
| Implementation of the device interface to represent the CPU. More... | |
| class | cpu_program |
| CPU base class for executable programs. More... | |
| class | cpu_program_builder |
| class | thread_pool |
| A fixed set of threads a loop's iterations are spread over. More... | |
Functions | |
| template<typename Body > | |
| void | parallel_for (thread_pool &pool, std::size_t count, std::size_t grain_size, const Body &body) |
| Run a loop, splitting it across a pool. | |
The backend that runs operations on the CPU of the host.
| void rexlib::cpu::parallel_for | ( | thread_pool & | pool, |
| std::size_t | count, | ||
| std::size_t | grain_size, | ||
| const Body & | body | ||
| ) |
Run a loop, splitting it across a pool.
Type-safe wrapper over thread_pool::run. body is referred to rather than copied, so nothing is allocated: the object lives in the caller's frame, which thread_pool::run does not outlive.
The body is invoked through a const reference, so a mutable lambda does not compile here. That is deliberate: the body runs concurrently on one and the same object, so state a chunk keeps to itself has to be created inside the body rather than captured by it. Mutating through what the body captures by reference is unaffected, and is what every caller does.
A free function rather than a member so that thread_pool is a class whose every method has a body in one translation unit, and the only thing needing to be a template lives on its own.
| Body | Functor invoked as body(begin, end) with the half-open range of iterations one chunk covers. |
| pool | The pool to spread the loop over. |
| count | Number of iterations. |
| grain_size | Smallest number of iterations worth handing to a thread of its own. Treated as one when zero. |
| body | The loop body. |
| Whatever | body throws. See thread_pool::run. |