Geant4 10.7.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

typedef TaskRunManagerpointer
 

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 44 of file TaskRunManager.hh.

Member Typedef Documentation

◆ pointer

Definition at line 47 of file TaskRunManager.hh.

Constructor & Destructor Documentation

◆ TaskRunManager()

TaskRunManager::TaskRunManager ( bool  useTBB = false)
explicit

Definition at line 65 of file TaskRunManager.cc.

66: m_is_initialized(false)
67, m_verbose(0)
68, m_workers(std::thread::hardware_concurrency())
69, m_task_queue(nullptr)
70, m_thread_pool(nullptr)
71, m_task_manager(nullptr)
72{
73 if(!GetPrivateMasterRunManager(false))
74 {
75 GetPrivateMasterRunManager(false) = this;
76 }
77
78#ifdef PTL_USE_TBB
79 auto _useTBB = GetEnv<bool>("FORCE_TBB", useTBB);
80 if(_useTBB)
81 useTBB = true;
82#endif
83
84 // handle TBB
86 m_workers = GetEnv<uint64_t>("PTL_NUM_THREADS", m_workers);
87}
TaskManager * m_task_manager
ThreadPool * m_thread_pool
VUserTaskQueue * m_task_queue
static void set_use_tbb(bool val)
Definition: ThreadPool.cc:100

◆ ~TaskRunManager()

TaskRunManager::~TaskRunManager ( )
virtual

Definition at line 91 of file TaskRunManager.cc.

91{}

Member Function Documentation

◆ GetInstance()

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

Definition at line 58 of file TaskRunManager.cc.

59{
60 return GetMasterRunManager(useTBB);
61}
static TaskRunManager * GetMasterRunManager(bool useTBB=false)

◆ GetMasterRunManager()

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

Definition at line 49 of file TaskRunManager.cc.

50{
51 static pointer& _instance = GetPrivateMasterRunManager(true, useTBB);
52 return _instance;
53}
TaskRunManager * pointer

Referenced by PTL::TaskManager::GetInstance(), GetInstance(), PTL::VTaskGroup::VTaskGroup(), PTL::VUserTaskQueue::VUserTaskQueue(), and PTL::VTaskGroup::wait().

◆ GetNumberActiveThreads()

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

Reimplemented in G4TaskRunManager.

Definition at line 62 of file TaskRunManager.hh.

63 {
64 return (m_thread_pool) ? m_thread_pool->size() : 0;
65 }
size_type size() const
Definition: ThreadPool.hh:151

Referenced by G4TaskRunManager::GetNumberActiveThreads().

◆ GetNumberOfThreads()

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

Reimplemented in G4TaskRunManager.

Definition at line 58 of file TaskRunManager.hh.

59 {
60 return (m_thread_pool) ? m_thread_pool->size() : 0;
61 }

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 74 of file TaskRunManager.hh.

74{ 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 96 of file TaskRunManager.cc.

97{
98 m_workers = n;
99
100 // create threadpool if needed + task manager
101 if(!m_thread_pool)
102 {
103 if(m_verbose > 0)
104 std::cout << "TaskRunManager :: Creating thread pool..." << std::endl;
106 if(m_verbose > 0)
107 std::cout << "TaskRunManager :: Creating task manager..." << std::endl;
109 }
110 // or resize
111 else if(m_workers != m_thread_pool->size())
112 {
113 if(m_verbose > 0)
114 {
115 std::cout << "TaskRunManager :: Resizing thread pool from "
116 << m_thread_pool->size() << " to " << m_workers << " threads ..."
117 << std::endl;
118 }
120 }
121
122 // create the joiners
124 {
125 if(m_verbose > 0)
126 std::cout << "TaskRunManager :: Using TBB..." << std::endl;
127 }
128 else
129 {
130 if(m_verbose > 0)
131 std::cout << "TaskRunManager :: Using ThreadPool..." << std::endl;
132 }
133
134 m_is_initialized = true;
135 if(m_verbose > 0)
136 std::cout << "TaskRunManager :: initialized..." << std::endl;
137}
static bool using_tbb()
Definition: ThreadPool.cc:92
void resize(size_type _n)
Definition: ThreadPool.hh:287

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

◆ IsInitialized()

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

Definition at line 73 of file TaskRunManager.hh.

73{ return m_is_initialized; }

◆ SetVerbose()

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

Definition at line 75 of file TaskRunManager.hh.

75{ m_verbose = val; }

Referenced by G4TaskRunManager::InitializeThreadPool().

◆ Terminate()

void TaskRunManager::Terminate ( )
virtual

Definition at line 142 of file TaskRunManager.cc.

143{
144 m_is_initialized = false;
146 delete m_task_manager;
147 delete m_thread_pool;
148 m_task_manager = nullptr;
149 m_thread_pool = nullptr;
150}
size_type destroy_threadpool()
Definition: ThreadPool.cc:366

Referenced by G4TaskRunManager::~G4TaskRunManager().

Member Data Documentation

◆ m_is_initialized

bool PTL::TaskRunManager::m_is_initialized = false
protected

Definition at line 87 of file TaskRunManager.hh.

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

◆ m_task_manager

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

Definition at line 92 of file TaskRunManager.hh.

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

◆ m_task_queue

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

Definition at line 90 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 88 of file TaskRunManager.hh.

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

◆ m_workers

uint64_t PTL::TaskRunManager::m_workers = 0
protected

Definition at line 89 of file TaskRunManager.hh.

Referenced by Initialize(), and TaskRunManager().


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