io-chess
UCI chess engine
Loading...
Searching...
No Matches
PersistentThreadPool Class Reference

A generic thread pool used for intra-evaluation parallelism and batch processing. More...

#include <PersistentThreadPool.hpp>

Classes

struct  Job

Public Member Functions

 PersistentThreadPool (int workers)
 ~PersistentThreadPool ()
 PersistentThreadPool (const PersistentThreadPool &)=delete
PersistentThreadPooloperator= (const PersistentThreadPool &)=delete
void parallel_for (int n, const std::function< void(int)> &fn)

Private Member Functions

void worker_loop ()

Static Private Member Functions

static void finish_one (const std::shared_ptr< Job > &job)
static void run_job (const std::shared_ptr< Job > &job)

Private Attributes

std::vector< std::thread > threads_
std::mutex mu_
std::condition_variable cv_
std::queue< std::shared_ptr< Job > > jobs_
bool stop_ = false

Detailed Description

A generic thread pool used for intra-evaluation parallelism and batch processing.

This thread pool is used by the MoEDoubleAccumulator in the core engine when the UCI EvalThreads option is set to >1. It parallelizes the evaluation of the neural network's internal spatial branches.

It is also used heavily by the standalone benchmark tools in src/tools/ to evaluate massive batches of positions simultaneously.

Constructor & Destructor Documentation

◆ PersistentThreadPool() [1/2]

PersistentThreadPool::PersistentThreadPool ( int workers)
inlineexplicit
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~PersistentThreadPool()

PersistentThreadPool::~PersistentThreadPool ( )
inline

◆ PersistentThreadPool() [2/2]

PersistentThreadPool::PersistentThreadPool ( const PersistentThreadPool & )
delete
Here is the call graph for this function:

Member Function Documentation

◆ finish_one()

void PersistentThreadPool::finish_one ( const std::shared_ptr< Job > & job)
inlinestaticprivate
Here is the caller graph for this function:

◆ operator=()

PersistentThreadPool & PersistentThreadPool::operator= ( const PersistentThreadPool & )
delete
Here is the call graph for this function:

◆ parallel_for()

void PersistentThreadPool::parallel_for ( int n,
const std::function< void(int)> & fn )
inline
Here is the call graph for this function:

◆ run_job()

void PersistentThreadPool::run_job ( const std::shared_ptr< Job > & job)
inlinestaticprivate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ worker_loop()

void PersistentThreadPool::worker_loop ( )
inlineprivate
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ cv_

std::condition_variable PersistentThreadPool::cv_
private

◆ jobs_

std::queue<std::shared_ptr<Job> > PersistentThreadPool::jobs_
private

◆ mu_

std::mutex PersistentThreadPool::mu_
private

◆ stop_

bool PersistentThreadPool::stop_ = false
private

◆ threads_

std::vector<std::thread> PersistentThreadPool::threads_
private

The documentation for this class was generated from the following file: