Geant4 11.3.0
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
 

Static Public Member Functions

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

Protected Attributes

bool m_is_initialized = false
 
uint64_t m_workers = 0
 
bool m_use_tbb = false
 
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()

PTL::TaskRunManager::TaskRunManager ( bool useTBB = false)
explicit

Definition at line 69 of file TaskRunManager.cc.

70: m_workers(std::thread::hardware_concurrency())
71, m_use_tbb(useTBB)
72{
73 if(!GetPrivateMasterRunManager())
74 GetPrivateMasterRunManager() = this;
75}

Referenced by G4TaskRunManager::G4TaskRunManager().

◆ ~TaskRunManager()

PTL::TaskRunManager::~TaskRunManager ( )
virtual

Definition at line 79 of file TaskRunManager.cc.

80{
81 if(GetPrivateMasterRunManager() == this)
82 GetPrivateMasterRunManager() = nullptr;
83}

Member Function Documentation

◆ GetInstance()

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

Definition at line 62 of file TaskRunManager.cc.

63{
64 return GetMasterRunManager(useTBB);
65}
static TaskRunManager * GetMasterRunManager(bool useTBB=false)

◆ GetMasterRunManager()

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

Definition at line 53 of file TaskRunManager.cc.

54{
55 auto& _v = GetPrivateMasterRunManager(true, useTBB);
56 return _v;
57}

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 G4SubEvtRunManager, and 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

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

◆ Initialize()

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

Reimplemented in G4SubEvtRunManager, and G4TaskRunManager.

Definition at line 88 of file TaskRunManager.cc.

89{
90 m_workers = n;
91
92 // create threadpool if needed + task manager
93 if(!m_thread_pool)
94 {
95 ThreadPool::Config cfg;
96 cfg.pool_size = m_workers;
97 cfg.task_queue = m_task_queue;
98 cfg.use_tbb = m_use_tbb;
99 m_thread_pool = new ThreadPool(cfg);
100 m_task_manager = new TaskManager(m_thread_pool);
101 }
102 // or resize
103 else if(m_workers != m_thread_pool->size())
104 {
105 m_thread_pool->resize(m_workers);
106 }
107
108 m_is_initialized = true;
109}
VUserTaskQueue * m_task_queue

Referenced by G4SubEvtRunManager::Initialize(), 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; }

◆ Terminate()

void PTL::TaskRunManager::Terminate ( )
virtual

Definition at line 114 of file TaskRunManager.cc.

115{
116 m_is_initialized = false;
117 if(m_thread_pool)
118 m_thread_pool->destroy_threadpool();
119 delete m_task_manager;
120 delete m_thread_pool;
121 m_task_manager = nullptr;
122 m_thread_pool = nullptr;
123}

Referenced by G4TaskRunManager::~G4TaskRunManager().

Member Data Documentation

◆ m_is_initialized

bool PTL::TaskRunManager::m_is_initialized = false
protected

Definition at line 83 of file TaskRunManager.hh.

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

◆ m_task_manager

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

Definition at line 88 of file TaskRunManager.hh.

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

◆ m_task_queue

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

Definition at line 86 of file TaskRunManager.hh.

Referenced by Initialize().

◆ m_thread_pool

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

◆ m_use_tbb

bool PTL::TaskRunManager::m_use_tbb = false
protected

Definition at line 85 of file TaskRunManager.hh.

Referenced by Initialize(), and TaskRunManager().

◆ m_workers

uint64_t PTL::TaskRunManager::m_workers = 0
protected

Definition at line 84 of file TaskRunManager.hh.

Referenced by Initialize(), and TaskRunManager().


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