Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
PTL::TaskRunManager Class Reference

#include <TaskRunManager.hh>

+ Inheritance diagram for PTL::TaskRunManager:

Public Types

using pointer = TaskRunManager*
 

Public Member Functions

 TaskRunManager (bool useTBB=false)
 
virtual ~TaskRunManager ()
 
virtual int GetNumberOfThreads () const
 
virtual size_t GetNumberActiveThreads () const
 
virtual void Initialize (uint64_t n=std::thread::hardware_concurrency())
 
virtual void Terminate ()
 
ThreadPoolGetThreadPool () const
 
TaskManagerGetTaskManager () const
 
bool IsInitialized () const
 
int GetVerbose () const
 
void SetVerbose (int val)
 

Static Public Member Functions

static TaskRunManagerGetInstance (bool useTBB=false)
 
static TaskRunManagerGetMasterRunManager (bool useTBB=false)
 

Protected Attributes

bool m_is_initialized = false
 
int m_verbose = 0
 
uint64_t m_workers = 0
 
VUserTaskQueuem_task_queue = nullptr
 
ThreadPoolm_thread_pool = nullptr
 
TaskManagerm_task_manager = nullptr
 

Detailed Description

Definition at line 41 of file TaskRunManager.hh.

Member Typedef Documentation

◆ pointer

Definition at line 44 of file TaskRunManager.hh.

Constructor & Destructor Documentation

◆ TaskRunManager()

TaskRunManager::TaskRunManager ( bool useTBB = false)
explicit

Definition at line 76 of file TaskRunManager.cc.

77: m_workers(std::thread::hardware_concurrency())
78{
79 if(!GetPrivateMasterRunManager())
80 GetPrivateMasterRunManager() = this;
81
82#if defined(PTL_USE_TBB)
83 auto _useTBB = GetEnv<bool>("PTL_FORCE_TBB", GetEnv<bool>("FORCE_TBB", useTBB));
84 if(_useTBB)
85 useTBB = true;
86#endif
87
88 // handle TBB
90 m_workers = GetEnv<uint64_t>("PTL_NUM_THREADS", m_workers);
91}
static void set_use_tbb(bool _v)
Tp GetEnv(const std::string &env_id, Tp _default=Tp())
Definition Utility.hh:155

◆ ~TaskRunManager()

TaskRunManager::~TaskRunManager ( )
virtual

Definition at line 95 of file TaskRunManager.cc.

96{
97 if(GetPrivateMasterRunManager() == this)
98 GetPrivateMasterRunManager() = nullptr;
99}

Member Function Documentation

◆ GetInstance()

TaskRunManager * TaskRunManager::GetInstance ( bool useTBB = false)
static

Definition at line 69 of file TaskRunManager.cc.

70{
71 return GetMasterRunManager(useTBB);
72}
static TaskRunManager * GetMasterRunManager(bool useTBB=false)

◆ GetMasterRunManager()

TaskRunManager * TaskRunManager::GetMasterRunManager ( bool useTBB = false)
static

Definition at line 60 of file TaskRunManager.cc.

61{
62 auto& _v = GetPrivateMasterRunManager(true, useTBB);
63 return _v;
64}

Referenced by PTL::internal::get_default_threadpool(), PTL::TaskManager::GetInstance(), GetInstance(), and PTL::VUserTaskQueue::VUserTaskQueue().

◆ GetNumberActiveThreads()

virtual size_t PTL::TaskRunManager::GetNumberActiveThreads ( ) const
inlinevirtual

Reimplemented in G4TaskRunManager.

Definition at line 59 of file TaskRunManager.hh.

60 {
61 return (m_thread_pool) ? m_thread_pool->size() : 0;
62 }
ThreadPool * m_thread_pool
size_type size() const

Referenced by G4TaskRunManager::GetNumberActiveThreads().

◆ GetNumberOfThreads()

virtual int PTL::TaskRunManager::GetNumberOfThreads ( ) const
inlinevirtual

Reimplemented in G4TaskRunManager.

Definition at line 55 of file TaskRunManager.hh.

56 {
57 return (m_thread_pool) ? (int)m_thread_pool->size() : 0;
58 }

Referenced by G4TaskRunManager::GetNumberOfThreads(), and PTL::VUserTaskQueue::VUserTaskQueue().

◆ GetTaskManager()

TaskManager * PTL::TaskRunManager::GetTaskManager ( ) const
inline

◆ GetThreadPool()

ThreadPool * PTL::TaskRunManager::GetThreadPool ( ) const
inline

◆ GetVerbose()

int PTL::TaskRunManager::GetVerbose ( ) const
inline

Definition at line 71 of file TaskRunManager.hh.

71{ return m_verbose; }

Referenced by G4TaskRunManager::InitializeThreadPool().

◆ Initialize()

void TaskRunManager::Initialize ( uint64_t n = std::thread::hardware_concurrency())
virtual

Reimplemented in G4TaskRunManager.

Definition at line 104 of file TaskRunManager.cc.

105{
106 m_workers = n;
107
108 // create threadpool if needed + task manager
109 if(!m_thread_pool)
110 {
111 if(m_verbose > 0)
112 std::cout << "TaskRunManager :: Creating thread pool..." << std::endl;
114 if(m_verbose > 0)
115 std::cout << "TaskRunManager :: Creating task manager..." << std::endl;
117 }
118 // or resize
119 else if(m_workers != m_thread_pool->size())
120 {
121 if(m_verbose > 0)
122 {
123 std::cout << "TaskRunManager :: Resizing thread pool from "
124 << m_thread_pool->size() << " to " << m_workers << " threads ..."
125 << std::endl;
126 }
128 }
129
130 // create the joiners
132 {
133 if(m_verbose > 0)
134 std::cout << "TaskRunManager :: Using TBB..." << std::endl;
135 }
136 else
137 {
138 if(m_verbose > 0)
139 std::cout << "TaskRunManager :: Using ThreadPool..." << std::endl;
140 }
141
142 m_is_initialized = true;
143 if(m_verbose > 0)
144 std::cout << "TaskRunManager :: initialized..." << std::endl;
145}
VUserTaskQueue * m_task_queue
static bool using_tbb()
void resize(size_type _n)

Referenced by G4TaskRunManager::Initialize(), and G4TaskRunManager::InitializeThreadPool().

◆ IsInitialized()

bool PTL::TaskRunManager::IsInitialized ( ) const
inline

Definition at line 70 of file TaskRunManager.hh.

70{ return m_is_initialized; }

◆ SetVerbose()

void PTL::TaskRunManager::SetVerbose ( int val)
inline

Definition at line 72 of file TaskRunManager.hh.

72{ m_verbose = val; }

Referenced by G4TaskRunManager::InitializeThreadPool().

◆ Terminate()

void TaskRunManager::Terminate ( )
virtual

Definition at line 150 of file TaskRunManager.cc.

151{
152 m_is_initialized = false;
153 if(m_thread_pool)
155 delete m_task_manager;
156 delete m_thread_pool;
157 m_task_manager = nullptr;
158 m_thread_pool = nullptr;
159}
size_type destroy_threadpool()

Referenced by G4TaskRunManager::~G4TaskRunManager().

Member Data Documentation

◆ m_is_initialized

bool PTL::TaskRunManager::m_is_initialized = false
protected

Definition at line 85 of file TaskRunManager.hh.

Referenced by Initialize(), IsInitialized(), and Terminate().

◆ m_task_manager

TaskManager* PTL::TaskRunManager::m_task_manager = nullptr
protected

Definition at line 90 of file TaskRunManager.hh.

Referenced by GetTaskManager(), Initialize(), and Terminate().

◆ m_task_queue

VUserTaskQueue* PTL::TaskRunManager::m_task_queue = nullptr
protected

Definition at line 88 of file TaskRunManager.hh.

Referenced by Initialize().

◆ m_thread_pool

ThreadPool* PTL::TaskRunManager::m_thread_pool = nullptr
protected

◆ m_verbose

int PTL::TaskRunManager::m_verbose = 0
protected

Definition at line 86 of file TaskRunManager.hh.

Referenced by GetVerbose(), Initialize(), and SetVerbose().

◆ m_workers

uint64_t PTL::TaskRunManager::m_workers = 0
protected

Definition at line 87 of file TaskRunManager.hh.

Referenced by Initialize(), and TaskRunManager().


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