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

#include <TaskManager.hh>

Public Types

typedef TaskManager this_type
 
typedef ThreadPool::size_type size_type
 

Public Member Functions

 TaskManager (ThreadPool *)
 
virtual ~TaskManager ()
 
 TaskManager (const this_type &)=delete
 
 TaskManager (this_type &&)=default
 
this_typeoperator= (const this_type &)=delete
 
this_typeoperator= (this_type &&)=default
 
ThreadPoolthread_pool () const
 
size_type size () const
 
void finalize ()
 
template<typename... Args>
void exec (Task< Args... > *_task)
 
template<typename RetT , typename FuncT , typename... Args>
std::future< RetT > async (FuncT &&func, Args &&... args)
 
template<typename RetT , typename FuncT >
std::future< RetT > async (FuncT &&func)
 
template<typename FuncT , typename... Args>
auto async (FuncT &&func, Args... args) -> std::future< decay_t< decltype(func(args...))> >
 
template<typename RetT , typename ArgT , typename FuncT , typename... Args>
Task< RetT, ArgT, Args... > * wrap (TaskGroup< RetT, ArgT > &tg, FuncT &&func, Args &&... args)
 
template<typename RetT , typename ArgT , typename FuncT >
Task< RetT, ArgT > * wrap (TaskGroup< RetT, ArgT > &tg, FuncT &&func)
 
template<typename RetT , typename ArgT , typename FuncT , typename... Args>
void exec (TaskGroup< RetT, ArgT > &tg, FuncT &&func, Args &&... args)
 
template<typename RetT , typename ArgT , typename FuncT >
void exec (TaskGroup< RetT, ArgT > &tg, FuncT &&func)
 
template<typename RetT , typename ArgT , typename FuncT , typename... Args>
void rexec (TaskGroup< RetT, ArgT > &tg, FuncT &&func, Args &&... args)
 
template<typename RetT , typename ArgT , typename FuncT >
void rexec (TaskGroup< RetT, ArgT > &tg, FuncT &&func)
 
template<typename FuncT , typename... Args>
void rexec (TaskGroup< void, void > &tg, FuncT &&func, Args &&... args)
 
template<typename FuncT >
void rexec (TaskGroup< void, void > &tg, FuncT &&func)
 

Static Public Member Functions

static TaskManagerGetInstance ()
 get the singleton pointer
 
static TaskManagerGetInstanceIfExists ()
 
static unsigned ncores ()
 

Protected Attributes

ThreadPoolm_pool = nullptr
 

Detailed Description

Definition at line 50 of file TaskManager.hh.

Member Typedef Documentation

◆ size_type

◆ this_type

Definition at line 53 of file TaskManager.hh.

Constructor & Destructor Documentation

◆ TaskManager() [1/3]

PTL::TaskManager::TaskManager ( ThreadPool _pool)
inlineexplicit

Definition at line 280 of file TaskManager.hh.

281: m_pool(_pool)
282{
283 if(!fgInstance())
284 fgInstance() = this;
285}
ThreadPool * m_pool
Definition: TaskManager.hh:235

◆ ~TaskManager()

PTL::TaskManager::~TaskManager ( )
inlinevirtual

Definition at line 289 of file TaskManager.hh.

290{
291 finalize();
292 if(fgInstance() == this)
293 fgInstance() = nullptr;
294}

◆ TaskManager() [2/3]

PTL::TaskManager::TaskManager ( const this_type )
delete

◆ TaskManager() [3/3]

PTL::TaskManager::TaskManager ( this_type &&  )
default

Member Function Documentation

◆ async() [1/3]

template<typename RetT , typename FuncT >
std::future< RetT > PTL::TaskManager::async ( FuncT &&  func)
inline

Definition at line 113 of file TaskManager.hh.

114 {
115 typedef PackagedTask<RetT> task_type;
116 typedef task_type* task_pointer;
117
118 task_pointer _ptask = new task_type(std::forward<FuncT>(func));
119 std::future<RetT> _f = _ptask->get_future();
120 m_pool->add_task(_ptask);
121 return _f;
122 }
size_type add_task(task_pointer task, int bin=-1)
Definition: ThreadPool.hh:328

◆ async() [2/3]

template<typename RetT , typename FuncT , typename... Args>
std::future< RetT > PTL::TaskManager::async ( FuncT &&  func,
Args &&...  args 
)
inline

Definition at line 100 of file TaskManager.hh.

101 {
102 typedef PackagedTask<RetT, Args...> task_type;
103 typedef task_type* task_pointer;
104
105 task_pointer _ptask =
106 new task_type(std::forward<FuncT>(func), std::forward<Args>(args)...);
107 std::future<RetT> _f = _ptask->get_future();
108 m_pool->add_task(_ptask);
109 return _f;
110 }

Referenced by G4TaskRunManagerKernel::ExecuteWorkerInit(), G4TaskRunManagerKernel::ExecuteWorkerTask(), and G4TaskRunManagerKernel::InitializeWorker().

◆ async() [3/3]

template<typename FuncT , typename... Args>
auto PTL::TaskManager::async ( FuncT &&  func,
Args...  args 
) -> std::future<decay_t<decltype(func(args...))>>
inline

Definition at line 125 of file TaskManager.hh.

127 {
128 using RetT = decay_t<decltype(func(args...))>;
129 typedef PackagedTask<RetT, Args...> task_type;
130
131 auto _ptask =
132 new task_type(std::forward<FuncT>(func), std::forward<Args>(args)...);
133 auto _f = _ptask->get_future();
134 m_pool->add_task(_ptask);
135 return _f;
136 }
typename std::decay< T >::type decay_t
Definition: Globals.hh:52

◆ exec() [1/3]

template<typename... Args>
void PTL::TaskManager::exec ( Task< Args... > *  _task)
inline

Definition at line 91 of file TaskManager.hh.

92 {
93 m_pool->add_task(_task);
94 }

◆ exec() [2/3]

template<typename RetT , typename ArgT , typename FuncT >
void PTL::TaskManager::exec ( TaskGroup< RetT, ArgT > &  tg,
FuncT &&  func 
)
inline

Definition at line 167 of file TaskManager.hh.

168 {
169 tg.exec(std::forward<FuncT>(func));
170 }

◆ exec() [3/3]

template<typename RetT , typename ArgT , typename FuncT , typename... Args>
void PTL::TaskManager::exec ( TaskGroup< RetT, ArgT > &  tg,
FuncT &&  func,
Args &&...  args 
)
inline

Definition at line 161 of file TaskManager.hh.

162 {
163 tg.exec(std::forward<FuncT>(func), std::forward<Args>(args)...);
164 }

◆ finalize()

void PTL::TaskManager::finalize ( )
inline

Definition at line 83 of file TaskManager.hh.

size_type destroy_threadpool()
Definition: ThreadPool.cc:366

◆ GetInstance()

PTL::TaskManager * PTL::TaskManager::GetInstance ( )
inlinestatic

get the singleton pointer

Definition at line 258 of file TaskManager.hh.

259{
260 if(!fgInstance())
261 {
262 auto nthreads = std::thread::hardware_concurrency();
263 std::cout << "Allocating mad::TaskManager with " << nthreads << " thread(s)..."
264 << std::endl;
265 new TaskManager(TaskRunManager::GetMasterRunManager()->GetThreadPool());
266 }
267 return fgInstance();
268}
TaskManager(ThreadPool *)
Definition: TaskManager.hh:280
static TaskRunManager * GetMasterRunManager(bool useTBB=false)

◆ GetInstanceIfExists()

PTL::TaskManager * PTL::TaskManager::GetInstanceIfExists ( )
inlinestatic

Definition at line 273 of file TaskManager.hh.

274{
275 return fgInstance();
276}

◆ ncores()

static unsigned PTL::TaskManager::ncores ( )
inlinestatic

Definition at line 70 of file TaskManager.hh.

70{ return std::thread::hardware_concurrency(); }

◆ operator=() [1/2]

this_type & PTL::TaskManager::operator= ( const this_type )
delete

◆ operator=() [2/2]

this_type & PTL::TaskManager::operator= ( this_type &&  )
default

◆ rexec() [1/4]

template<typename RetT , typename ArgT , typename FuncT >
void PTL::TaskManager::rexec ( TaskGroup< RetT, ArgT > &  tg,
FuncT &&  func 
)
inline

Definition at line 179 of file TaskManager.hh.

180 {
181 tg.exec(std::forward<FuncT>(func));
182 }

◆ rexec() [2/4]

template<typename RetT , typename ArgT , typename FuncT , typename... Args>
void PTL::TaskManager::rexec ( TaskGroup< RetT, ArgT > &  tg,
FuncT &&  func,
Args &&...  args 
)
inline

Definition at line 173 of file TaskManager.hh.

174 {
175 tg.exec(std::forward<FuncT>(func), std::forward<Args>(args)...);
176 }

◆ rexec() [3/4]

template<typename FuncT >
void PTL::TaskManager::rexec ( TaskGroup< void, void > &  tg,
FuncT &&  func 
)
inline

Definition at line 193 of file TaskManager.hh.

194 {
195 tg.exec(std::forward<FuncT>(func));
196 }

◆ rexec() [4/4]

template<typename FuncT , typename... Args>
void PTL::TaskManager::rexec ( TaskGroup< void, void > &  tg,
FuncT &&  func,
Args &&...  args 
)
inline

Definition at line 187 of file TaskManager.hh.

188 {
189 tg.exec(std::forward<FuncT>(func), std::forward<Args>(args)...);
190 }

◆ size()

size_type PTL::TaskManager::size ( ) const
inline

Definition at line 79 of file TaskManager.hh.

79{ return m_pool->size(); }
size_type size() const
Definition: ThreadPool.hh:151

◆ thread_pool()

ThreadPool * PTL::TaskManager::thread_pool ( ) const
inline

Definition at line 75 of file TaskManager.hh.

75{ return m_pool; }

◆ wrap() [1/2]

template<typename RetT , typename ArgT , typename FuncT >
Task< RetT, ArgT > * PTL::TaskManager::wrap ( TaskGroup< RetT, ArgT > &  tg,
FuncT &&  func 
)
inline

Definition at line 151 of file TaskManager.hh.

152 {
153 return tg.wrap(std::forward<FuncT>(func));
154 }

◆ wrap() [2/2]

template<typename RetT , typename ArgT , typename FuncT , typename... Args>
Task< RetT, ArgT, Args... > * PTL::TaskManager::wrap ( TaskGroup< RetT, ArgT > &  tg,
FuncT &&  func,
Args &&...  args 
)
inline

Definition at line 144 of file TaskManager.hh.

146 {
147 return tg.wrap(std::forward<FuncT>(func), std::forward<Args>(args)...);
148 }

Member Data Documentation

◆ m_pool

ThreadPool* PTL::TaskManager::m_pool = nullptr
protected

Definition at line 235 of file TaskManager.hh.

Referenced by async(), exec(), finalize(), size(), and thread_pool().


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