Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
|
#include <ThreadPool.hh>
Public Types | |
template<typename KeyT , typename MappedT , typename HashT = KeyT> | |
using | uomap = std::unordered_map< KeyT, MappedT, std::hash< HashT > > |
using | size_type = size_t |
using | task_count_type = std::shared_ptr< std::atomic_uintmax_t > |
using | atomic_int_type = std::shared_ptr< std::atomic_uintmax_t > |
using | pool_state_type = std::shared_ptr< std::atomic_short > |
using | atomic_bool_type = std::shared_ptr< std::atomic_bool > |
using | task_type = VTask |
using | lock_t = std::shared_ptr< Mutex > |
using | condition_t = std::shared_ptr< Condition > |
using | task_pointer = task_type * |
using | task_queue_t = VUserTaskQueue |
typedef std::deque< ThreadId > | thread_list_t |
typedef std::vector< bool > | bool_list_t |
typedef std::map< ThreadId, uintmax_t > | thread_id_map_t |
typedef std::map< uintmax_t, ThreadId > | thread_index_map_t |
using | thread_vec_t = std::vector< Thread > |
typedef std::function< void()> | initialize_func_t |
typedef std::function< intmax_t(intmax_t)> | affinity_func_t |
Public Member Functions | |
ThreadPool (const size_type &pool_size, VUserTaskQueue *task_queue=nullptr, bool _use_affinity=GetEnv< bool >("PTL_CPU_AFFINITY", false), const affinity_func_t &=[](intmax_t) { static std::atomic< intmax_t > assigned;intmax_t _assign=assigned++;return _assign % Thread::hardware_concurrency();}) | |
virtual | ~ThreadPool () |
ThreadPool (const ThreadPool &)=delete | |
ThreadPool (ThreadPool &&)=default | |
ThreadPool & | operator= (const ThreadPool &)=delete |
ThreadPool & | operator= (ThreadPool &&)=default |
size_type | initialize_threadpool (size_type) |
size_type | destroy_threadpool () |
size_type | stop_thread () |
template<typename FuncT > | |
void | execute_on_all_threads (FuncT &&_func) |
size_type | add_task (task_pointer task, int bin=-1) |
template<typename ListT > | |
size_type | add_tasks (ListT &) |
Thread * | get_thread (size_type _n) const |
Thread * | get_thread (std::thread::id id) const |
task_queue_t * | get_queue () const |
void | set_initialization (initialize_func_t f) |
void | reset_initialization () |
const pool_state_type & | state () const |
size_type | size () const |
void | resize (size_type _n) |
bool | using_affinity () const |
bool | is_alive () |
void | notify () |
void | notify_all () |
void | notify (size_type) |
bool | is_initialized () const |
int | get_active_threads_count () const |
void | set_affinity (affinity_func_t f) |
void | set_affinity (intmax_t i, Thread &) |
void | set_verbose (int n) |
int | get_verbose () const |
bool | is_master () const |
Static Public Member Functions | |
static bool | using_tbb () |
static void | set_use_tbb (bool val) |
static tbb_global_control_t *& | tbb_global_control () |
static const thread_id_map_t & | get_thread_ids () |
static uintmax_t | get_this_thread_id () |
Protected Member Functions | |
void | execute_thread (VUserTaskQueue *) |
int | insert (const task_pointer &, int=-1) |
int | run_on_this (task_pointer) |
void | record_entry () |
void | record_exit () |
Static Protected Member Functions | |
static void | start_thread (ThreadPool *, intmax_t=-1) |
Definition at line 63 of file ThreadPool.hh.
typedef std::function<intmax_t(intmax_t)> PTL::ThreadPool::affinity_func_t |
Definition at line 89 of file ThreadPool.hh.
using PTL::ThreadPool::atomic_bool_type = std::shared_ptr<std::atomic_bool> |
Definition at line 74 of file ThreadPool.hh.
using PTL::ThreadPool::atomic_int_type = std::shared_ptr<std::atomic_uintmax_t> |
Definition at line 72 of file ThreadPool.hh.
typedef std::vector<bool> PTL::ThreadPool::bool_list_t |
Definition at line 83 of file ThreadPool.hh.
using PTL::ThreadPool::condition_t = std::shared_ptr<Condition> |
Definition at line 78 of file ThreadPool.hh.
typedef std::function<void()> PTL::ThreadPool::initialize_func_t |
Definition at line 88 of file ThreadPool.hh.
using PTL::ThreadPool::lock_t = std::shared_ptr<Mutex> |
Definition at line 77 of file ThreadPool.hh.
using PTL::ThreadPool::pool_state_type = std::shared_ptr<std::atomic_short> |
Definition at line 73 of file ThreadPool.hh.
using PTL::ThreadPool::size_type = size_t |
Definition at line 70 of file ThreadPool.hh.
using PTL::ThreadPool::task_count_type = std::shared_ptr<std::atomic_uintmax_t> |
Definition at line 71 of file ThreadPool.hh.
using PTL::ThreadPool::task_pointer = task_type* |
Definition at line 79 of file ThreadPool.hh.
Definition at line 80 of file ThreadPool.hh.
using PTL::ThreadPool::task_type = VTask |
Definition at line 76 of file ThreadPool.hh.
typedef std::map<ThreadId, uintmax_t> PTL::ThreadPool::thread_id_map_t |
Definition at line 84 of file ThreadPool.hh.
typedef std::map<uintmax_t, ThreadId> PTL::ThreadPool::thread_index_map_t |
Definition at line 85 of file ThreadPool.hh.
typedef std::deque<ThreadId> PTL::ThreadPool::thread_list_t |
Definition at line 82 of file ThreadPool.hh.
using PTL::ThreadPool::thread_vec_t = std::vector<Thread> |
Definition at line 86 of file ThreadPool.hh.
using PTL::ThreadPool::uomap = std::unordered_map<KeyT, MappedT, std::hash<HashT> > |
Definition at line 67 of file ThreadPool.hh.
ThreadPool::ThreadPool | ( | const size_type & | pool_size, |
VUserTaskQueue * | task_queue = nullptr , |
||
bool | _use_affinity = GetEnv<bool>("PTL_CPU_AFFINITY", false) , |
||
const affinity_func_t & | _affinity_func = [](intmax_t) { static std::atomic<intmax_t> assigned; intmax_t _assign = assigned++; return _assign % Thread::hardware_concurrency(); } |
||
) |
Definition at line 138 of file ThreadPool.cc.
|
virtual |
Definition at line 172 of file ThreadPool.cc.
|
delete |
|
default |
|
inline |
Definition at line 328 of file ThreadPool.hh.
Referenced by PTL::TaskManager::async(), PTL::TaskGroup< Tp, Arg >::exec(), PTL::TaskManager::exec(), and PTL::TaskGroup< Tp, Arg >::run().
|
inline |
Definition at line 343 of file ThreadPool.hh.
ThreadPool::size_type ThreadPool::destroy_threadpool | ( | ) |
Definition at line 366 of file ThreadPool.cc.
Referenced by PTL::TaskManager::finalize(), PTL::TaskRunManager::Terminate(), and G4TaskRunManager::~G4TaskRunManager().
|
inline |
Definition at line 375 of file ThreadPool.hh.
Referenced by G4TaskRunManager::CreateAndStartWorkers(), G4TaskRunManager::RequestWorkersProcessCommandsStack(), G4TaskRunManager::TerminateWorkers(), and G4TaskRunManager::WaitForEndEventLoopWorkers().
|
protected |
Definition at line 520 of file ThreadPool.cc.
|
inline |
Definition at line 161 of file ThreadPool.hh.
|
inline |
Definition at line 135 of file ThreadPool.hh.
Referenced by execute_on_all_threads(), PTL::ThreadData::update(), and PTL::VTaskGroup::wait().
|
static |
Definition at line 120 of file ThreadPool.cc.
Referenced by PTL::UserTaskQueue::GetThreadBin(), initialize_threadpool(), G4TaskRunManagerKernel::InitializeWorker(), PTL::VTask::operator--(), and PTL::UserTaskQueue::UserTaskQueue().
Thread * PTL::ThreadPool::get_thread | ( | std::thread::id | id | ) | const |
|
static |
Definition at line 112 of file ThreadPool.cc.
|
inline |
Definition at line 170 of file ThreadPool.hh.
Referenced by execute_on_all_threads().
ThreadPool::size_type ThreadPool::initialize_threadpool | ( | size_type | proposed_size | ) |
Definition at line 223 of file ThreadPool.cc.
Referenced by resize().
|
inlineprotected |
Definition at line 317 of file ThreadPool.hh.
Referenced by add_task().
|
inline |
Definition at line 156 of file ThreadPool.hh.
Referenced by PTL::VTaskGroup::wait().
bool ThreadPool::is_initialized | ( | ) | const |
Definition at line 193 of file ThreadPool.cc.
|
inline |
Definition at line 171 of file ThreadPool.hh.
|
inline |
Definition at line 240 of file ThreadPool.hh.
Referenced by add_tasks(), and insert().
|
inline |
Definition at line 259 of file ThreadPool.hh.
|
inline |
Definition at line 251 of file ThreadPool.hh.
|
delete |
|
default |
|
inlineprotected |
Definition at line 187 of file ThreadPool.hh.
|
inlineprotected |
Definition at line 193 of file ThreadPool.hh.
|
inline |
Definition at line 141 of file ThreadPool.hh.
|
inline |
Definition at line 287 of file ThreadPool.hh.
Referenced by PTL::TaskRunManager::Initialize(), and G4TaskRunManager::SetNumberOfThreads().
|
inlineprotected |
Definition at line 296 of file ThreadPool.hh.
Referenced by add_task().
|
inline |
Definition at line 166 of file ThreadPool.hh.
Referenced by initialize_threadpool().
void ThreadPool::set_affinity | ( | intmax_t | i, |
Thread & | _thread | ||
) |
Definition at line 201 of file ThreadPool.cc.
|
inline |
Definition at line 140 of file ThreadPool.hh.
|
static |
Definition at line 100 of file ThreadPool.cc.
Referenced by G4TaskRunManager::G4TaskRunManager(), and PTL::TaskRunManager::TaskRunManager().
|
inline |
Definition at line 169 of file ThreadPool.hh.
|
inline |
Definition at line 151 of file ThreadPool.hh.
Referenced by G4TaskRunManager::ComputeNumberOfTasks(), execute_on_all_threads(), PTL::TaskRunManager::GetNumberActiveThreads(), PTL::TaskRunManager::GetNumberOfThreads(), PTL::TaskRunManager::Initialize(), G4TaskRunManagerKernel::InitializeWorker(), notify(), PTL::TaskManager::size(), and PTL::VTaskGroup::wait().
|
staticprotected |
Definition at line 72 of file ThreadPool.cc.
Referenced by initialize_threadpool().
|
inline |
Definition at line 149 of file ThreadPool.hh.
Referenced by PTL::VTaskGroup::wait().
ThreadPool::size_type ThreadPool::stop_thread | ( | ) |
Definition at line 479 of file ThreadPool.cc.
Referenced by initialize_threadpool().
|
inlinestatic |
Definition at line 280 of file ThreadPool.hh.
Referenced by destroy_threadpool(), execute_on_all_threads(), and initialize_threadpool().
|
inline |
Definition at line 155 of file ThreadPool.hh.
|
static |
Definition at line 92 of file ThreadPool.cc.
Referenced by PTL::TaskRunManager::Initialize(), and G4TaskRunManager::InitializeThreadPool().