|
Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
|
Thread pool for parallel path tracking within a single MPI worker rank. More...
#include <thread_pool.hpp>
Public Member Functions | |
| WorkerThreadPool (int n_threads, StateFactory state_factory, TrackFn track_fn) | |
| Construct the pool and start n_threads worker threads, each with its own state. | |
| void | submit (TaskT task) |
| Submit a task to be tracked by a worker thread. | |
| ResultT | collect () |
| Block until one result is available, then return it. | |
| std::optional< ResultT > | try_collect () |
| Return a result if one is ready, otherwise std::nullopt (non-blocking). | |
| void | shutdown () |
| Signal all threads to exit and join (call only after all results are collected). | |
Thread pool for parallel path tracking within a single MPI worker rank.
| TaskT | Task type received from the MPI manager. |
| ResultT | Result type sent back after tracking. |
| StateFactory | Callable () -> StateT: constructs a per-thread state struct (e.g. containing a System copy + Tracker copy) once at thread startup. |
| TrackFn | Callable (StateT&, TaskT const&) -> ResultT: tracks one path using the thread-local state. |
The StateFactory approach sidesteps the "tracker holds a reference to an external System" issue: each thread owns its state struct, so System and Tracker lifetimes are co-managed.
|
inline |
Construct the pool and start n_threads worker threads, each with its own state.
| n_threads | The number of worker threads to start. |
| state_factory | Callable building each thread's per-thread state. |
| track_fn | Callable tracking one path using the thread-local state. |
|
inline |
Block until one result is available, then return it.
|
inline |
Signal all threads to exit and join (call only after all results are collected).
|
inline |
Submit a task to be tracked by a worker thread.
|
inline |
Return a result if one is ready, otherwise std::nullopt (non-blocking).