Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
bertini::parallel::WorkerThreadPool< TaskT, ResultT, StateFactory, TrackFn > Class Template Reference

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).

Detailed Description

template<typename TaskT, typename ResultT, typename StateFactory, typename TrackFn>
class bertini::parallel::WorkerThreadPool< TaskT, ResultT, StateFactory, TrackFn >

Thread pool for parallel path tracking within a single MPI worker rank.

Template Parameters
TaskTTask type received from the MPI manager.
ResultTResult type sent back after tracking.
StateFactoryCallable () -> StateT: constructs a per-thread state struct (e.g. containing a System copy + Tracker copy) once at thread startup.
TrackFnCallable (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.

Constructor & Destructor Documentation

◆ WorkerThreadPool()

template<typename TaskT, typename ResultT, typename StateFactory, typename TrackFn>
bertini::parallel::WorkerThreadPool< TaskT, ResultT, StateFactory, TrackFn >::WorkerThreadPool ( int n_threads,
StateFactory state_factory,
TrackFn track_fn )
inline

Construct the pool and start n_threads worker threads, each with its own state.

Parameters
n_threadsThe number of worker threads to start.
state_factoryCallable building each thread's per-thread state.
track_fnCallable tracking one path using the thread-local state.

Member Function Documentation

◆ collect()

template<typename TaskT, typename ResultT, typename StateFactory, typename TrackFn>
ResultT bertini::parallel::WorkerThreadPool< TaskT, ResultT, StateFactory, TrackFn >::collect ( )
inline

Block until one result is available, then return it.

◆ shutdown()

template<typename TaskT, typename ResultT, typename StateFactory, typename TrackFn>
void bertini::parallel::WorkerThreadPool< TaskT, ResultT, StateFactory, TrackFn >::shutdown ( )
inline

Signal all threads to exit and join (call only after all results are collected).

◆ submit()

template<typename TaskT, typename ResultT, typename StateFactory, typename TrackFn>
void bertini::parallel::WorkerThreadPool< TaskT, ResultT, StateFactory, TrackFn >::submit ( TaskT task)
inline

Submit a task to be tracked by a worker thread.

◆ try_collect()

template<typename TaskT, typename ResultT, typename StateFactory, typename TrackFn>
std::optional< ResultT > bertini::parallel::WorkerThreadPool< TaskT, ResultT, StateFactory, TrackFn >::try_collect ( )
inline

Return a result if one is ready, otherwise std::nullopt (non-blocking).