LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
lbann::thread_pool Class Reference

#include <thread_pool.hpp>

Collaboration diagram for lbann::thread_pool:
[legend]

Classes

class  thread_joiner
 RAII object that destroys threads. More...
 

Public Types

using thread_container_type = std::vector< std::thread >
 
using size_type = typename thread_container_type::size_type
 

Public Member Functions

 thread_pool ()
 Construct an empty threadpool. Size must be set with launch(). More...
 
 thread_pool (size_type max_threads)
 Construct a threadpool of a given size. More...
 
 ~thread_pool ()
 Destroy the threadpool. More...
 
void launch_threads (size_type num_threads)
 Launch the threads. More...
 
void launch_pinned_threads (size_type num_threads, int cpu_offset)
 Launch the threads and pin them to the Hyperthreaded cores. More...
 
void reap_threads ()
 
void relaunch_pinned_threads (size_type num_threads)
 
template<typename FunctionT >
std::future< typename std::result_of< FunctionT()>::type > submit_job (FunctionT func)
 Submit a job to the pool's queue. More...
 
template<typename FunctionT >
void submit_job_to_work_group (FunctionT func)
 Submit a job to the pool's queue and place the future into a work group. More...
 
bool finish_work_group ()
 Wait for all of the jobs in a work group to finish. More...
 
size_type get_num_threads () const noexcept
 Query the number of worker threads actually present. More...
 
int get_local_thread_id ()
 Convert the C++ thread id into a local thread pool id. More...
 
int get_threads_offset ()
 Convert the C++ thread id into a local thread pool id. More...
 

Private Member Functions

void do_thread_work_ ()
 The task executed by each thread. More...
 

Private Attributes

thread_container_type threads_
 Container holding the threads. More...
 
thread_safe_queue< type_erased_functionglobal_work_queue_
 The thread-safe work queue. More...
 
thread_joiner thread_joiner_
 RAII "deleter" for the threads. More...
 
std::atomic< bool > all_work_done_
 Flag to track if more work is to be done. More...
 
std::mutex m_thread_map_mutex
 
std::unordered_map< std::thread::id, int > m_thread_id_to_local_id_map
 
std::vector< std::future< bool > > m_work_group
 Work Group. More...
 
int m_threads_offset
 

Detailed Description

Definition at line 51 of file thread_pool.hpp.

Member Typedef Documentation

◆ size_type

using lbann::thread_pool::size_type = typename thread_container_type::size_type

Definition at line 55 of file thread_pool.hpp.

◆ thread_container_type

using lbann::thread_pool::thread_container_type = std::vector<std::thread>

Definition at line 54 of file thread_pool.hpp.

Constructor & Destructor Documentation

◆ thread_pool() [1/2]

lbann::thread_pool::thread_pool ( )

Construct an empty threadpool. Size must be set with launch().

◆ thread_pool() [2/2]

lbann::thread_pool::thread_pool ( size_type  max_threads)

Construct a threadpool of a given size.

Parameters
max_threadsTotal threads available. max_threads-1 worker threads will be launched.

◆ ~thread_pool()

lbann::thread_pool::~thread_pool ( )
inline

Destroy the threadpool.

Definition at line 89 of file thread_pool.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ do_thread_work_()

void lbann::thread_pool::do_thread_work_ ( )
private

The task executed by each thread.

Here is the caller graph for this function:

◆ finish_work_group()

bool lbann::thread_pool::finish_work_group ( )
inline

Wait for all of the jobs in a work group to finish.

Definition at line 128 of file thread_pool.hpp.

◆ get_local_thread_id()

int lbann::thread_pool::get_local_thread_id ( )

Convert the C++ thread id into a local thread pool id.

Here is the caller graph for this function:

◆ get_num_threads()

size_type lbann::thread_pool::get_num_threads ( ) const
inlinenoexcept

Query the number of worker threads actually present.

Definition at line 145 of file thread_pool.hpp.

Here is the call graph for this function:

◆ get_threads_offset()

int lbann::thread_pool::get_threads_offset ( )
inline

Convert the C++ thread id into a local thread pool id.

Definition at line 151 of file thread_pool.hpp.

Here is the call graph for this function:

◆ launch_pinned_threads()

void lbann::thread_pool::launch_pinned_threads ( size_type  num_threads,
int  cpu_offset 
)

Launch the threads and pin them to the Hyperthreaded cores.

Here is the caller graph for this function:

◆ launch_threads()

void lbann::thread_pool::launch_threads ( size_type  num_threads)

Launch the threads.

Here is the caller graph for this function:

◆ reap_threads()

void lbann::thread_pool::reap_threads ( )

Wake and terminate all threads in the pool

Here is the caller graph for this function:

◆ relaunch_pinned_threads()

void lbann::thread_pool::relaunch_pinned_threads ( size_type  num_threads)

Reap all threads in the pool and relaunch pinned threads

Here is the caller graph for this function:

◆ submit_job()

template<typename FunctionT >
std::future<typename std::result_of<FunctionT()>::type> lbann::thread_pool::submit_job ( FunctionT  func)
inline

Submit a job to the pool's queue.

Definition at line 103 of file thread_pool.hpp.

◆ submit_job_to_work_group()

template<typename FunctionT >
void lbann::thread_pool::submit_job_to_work_group ( FunctionT  func)
inline

Submit a job to the pool's queue and place the future into a work group.

Definition at line 116 of file thread_pool.hpp.

Member Data Documentation

◆ all_work_done_

std::atomic<bool> lbann::thread_pool::all_work_done_
private

Flag to track if more work is to be done.

Definition at line 172 of file thread_pool.hpp.

◆ global_work_queue_

thread_safe_queue<type_erased_function> lbann::thread_pool::global_work_queue_
private

The thread-safe work queue.

Definition at line 166 of file thread_pool.hpp.

◆ m_thread_id_to_local_id_map

std::unordered_map<std::thread::id, int> lbann::thread_pool::m_thread_id_to_local_id_map
private

Definition at line 175 of file thread_pool.hpp.

◆ m_thread_map_mutex

std::mutex lbann::thread_pool::m_thread_map_mutex
private

Definition at line 174 of file thread_pool.hpp.

◆ m_threads_offset

int lbann::thread_pool::m_threads_offset
private

Definition at line 180 of file thread_pool.hpp.

◆ m_work_group

std::vector<std::future<bool> > lbann::thread_pool::m_work_group
private

Work Group.

Definition at line 178 of file thread_pool.hpp.

◆ thread_joiner_

thread_joiner lbann::thread_pool::thread_joiner_
private

RAII "deleter" for the threads.

Definition at line 169 of file thread_pool.hpp.

◆ threads_

thread_container_type lbann::thread_pool::threads_
private

Container holding the threads.

Definition at line 163 of file thread_pool.hpp.


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