Class SPMD_ThreadPool
Defined in File spmd_threadpool.h
Class Documentation
-
class SPMD_ThreadPool
Single-Program Multiple-Data (SPMD) thread pool.
A fixed set of worker threads repeatedly executes the same callable in “epochs”. Each epoch publishes one task and wakes all workers. Each worker calls the task with its own rank (thread index). The caller thread waits until all workers finish the current epoch.
This design avoids repeated thread creation/join overhead when the number of workers is stable.
Note
Unless otherwise stated, public member functions are not thread-safe with respect to concurrent calls from multiple external threads.
Public Functions
-
SPMD_ThreadPool() = default
-
explicit SPMD_ThreadPool(std::size_t n)
Constructor with a fixed number of worker threads.
-
SPMD_ThreadPool(const SPMD_ThreadPool&) = delete
-
SPMD_ThreadPool &operator=(const SPMD_ThreadPool&) = delete
-
~SPMD_ThreadPool()
-
inline std::size_t GetSize() const noexcept
-
inline bool IsInitialized() const noexcept
-
void Resize(std::size_t n)
Resize the numnber of worker threads.
-
void Stop()
Stop workers and join threads.
Note
This method is safe to call multiple times.
-
SPMD_ThreadPool() = default