Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
PTL::TaskGroup< Tp, Arg > Class Template Reference

#include <TaskGroup.hh>

+ Inheritance diagram for PTL::TaskGroup< Tp, Arg >:

Public Types

typedef decay_t< Arg > ArgTp
 
typedef Tp result_type
 
typedef TaskGroup< Tp, Arg > this_type
 
typedef std::promise< ArgTppromise_type
 
typedef std::future< ArgTpfuture_type
 
typedef std::packaged_task< ArgTp()> packaged_task_type
 
typedef list_type< future_typetask_list_t
 
typedef JoinFunction< Tp, Arg >::Type join_type
 
typedef task_list_t::iterator iterator
 
typedef task_list_t::reverse_iterator reverse_iterator
 
typedef task_list_t::const_iterator const_iterator
 
typedef task_list_t::const_reverse_iterator const_reverse_iterator
 
template<typename... Args>
using task_type = Task< ArgTp, decay_t< Args >... >
 
- Public Types inherited from PTL::VTaskGroup
template<typename Tp >
using container_type = std::vector< Tp >
 
template<typename Tp >
using list_type = std::vector< Tp >
 
typedef VTaskGroup this_type
 
typedef std::thread::id tid_type
 
typedef VTask task_type
 
typedef uintmax_t size_type
 
typedef Mutex lock_t
 
typedef std::atomic_intmax_t atomic_int
 
typedef std::atomic_uintmax_t atomic_uint
 
typedef Condition condition_t
 
typedef task_typetask_pointer
 
typedef container_type< task_pointervtask_list_type
 
- Public Types inherited from PTL::TaskAllocator< Type >
typedef Type value_type
 
typedef size_t size_type
 
typedef ptrdiff_t difference_type
 
typedef Typepointer
 
typedef const Typeconst_pointer
 
typedef Typereference
 
typedef const Typeconst_reference
 
typedef TaskAllocatorImpl< Typeallocator_type
 
- Public Types inherited from PTL::TaskAllocatorImpl< Type >
typedef Type value_type
 
typedef size_t size_type
 
typedef ptrdiff_t difference_type
 
typedef Typepointer
 
typedef const Typeconst_pointer
 
typedef Typereference
 
typedef const Typeconst_reference
 

Public Member Functions

template<typename Func >
 TaskGroup (Func &&_join, ThreadPool *_tp=nullptr)
 
template<typename Up = Tp, enable_if_t< std::is_same< Up, void >::value, int > = 0>
 TaskGroup (ThreadPool *_tp=nullptr)
 
virtual ~TaskGroup ()
 
 TaskGroup (const this_type &)=delete
 
 TaskGroup (this_type &&rhs)=default
 
this_typeoperator= (const this_type &rhs)=delete
 
this_typeoperator= (this_type &&rhs)=default
 
template<typename Up >
Up * operator+= (Up *_task)
 
template<typename Func , typename... Args>
task_type< Args... > * wrap (Func &&func, Args... args)
 
template<typename Func , typename... Args>
void exec (Func &&func, Args... args)
 
template<typename Func , typename... Args>
void run (Func &&func, Args... args)
 
template<typename Func , typename... Args>
void parallel_for (const intmax_t &nitr, const intmax_t &chunks, Func &&func, Args... args)
 
task_list_tget_tasks ()
 
const task_list_tget_tasks () const
 
itr_t begin ()
 
itr_t end ()
 
citr_t begin () const
 
citr_t end () const
 
citr_t cbegin () const
 
citr_t cend () const
 
ritr_t rbegin ()
 
ritr_t rend ()
 
critr_t rbegin () const
 
critr_t rend () const
 
template<typename Up = Tp, enable_if_t<!std::is_void< Up >::value, int > = 0>
Up join (Up accum={})
 
template<typename Up = Tp, typename Rp = Arg, enable_if_t< std::is_void< Up >::value &&std::is_void< Rp >::value, int > = 0>
void join ()
 
template<typename Up = Tp, typename Rp = Arg, enable_if_t< std::is_void< Up >::value &&!std::is_void< Rp >::value, int > = 0>
void join ()
 
void clear ()
 
- Public Member Functions inherited from PTL::VTaskGroup
 VTaskGroup (ThreadPool *tp=nullptr)
 
virtual ~VTaskGroup ()
 
 VTaskGroup (const this_type &)=delete
 
 VTaskGroup (this_type &&rhs)=default
 
this_typeoperator= (const this_type &)=delete
 
this_typeoperator= (this_type &&rhs)=default
 
virtual void wait ()
 
intmax_t operator++ ()
 
intmax_t operator++ (int)
 
intmax_t operator-- ()
 
intmax_t operator-- (int)
 
intmax_t size () const
 
std::shared_ptr< condition_ttask_cond ()
 
const uintmax_t & id () const
 
void set_pool (ThreadPool *tp)
 
ThreadPool *& pool ()
 
ThreadPoolpool () const
 
void clear ()
 
virtual bool is_native_task_group () const
 
virtual bool is_master () const
 
virtual intmax_t pending ()
 
- Public Member Functions inherited from PTL::TaskAllocator< Type >
void * operator new (size_type)
 
void operator delete (void *ptr)
 
- Public Member Functions inherited from PTL::TaskAllocatorImpl< Type >
 TaskAllocatorImpl ()
 
 ~TaskAllocatorImpl ()
 
TypeMallocSingle ()
 
void FreeSingle (Type *anElement)
 
void ResetStorage () override
 
size_t GetAllocatedSize () const override
 
int GetNoPages () const override
 
size_t GetPageSize () const override
 
void IncreasePageSize (unsigned int sz) override
 
const char * GetPoolType () const override
 
template<class U >
 TaskAllocatorImpl (const TaskAllocatorImpl< U > &right) throw ()
 
pointer address (reference r) const
 
const_pointer address (const_reference r) const
 
pointer allocate (size_type n, void *=0)
 
void deallocate (pointer p, size_type n)
 
void construct (pointer p, const Type &val)
 
void destroy (pointer p)
 
size_type max_size () const throw ()
 
- Public Member Functions inherited from PTL::TaskAllocatorBase
 TaskAllocatorBase ()
 
virtual ~TaskAllocatorBase ()
 
virtual void ResetStorage ()=0
 
virtual size_t GetAllocatedSize () const =0
 
virtual int GetNoPages () const =0
 
virtual size_t GetPageSize () const =0
 
virtual void IncreasePageSize (unsigned int sz)=0
 
virtual const char * GetPoolType () const =0
 

Protected Types

typedef iterator itr_t
 
typedef const_iterator citr_t
 
typedef reverse_iterator ritr_t
 
typedef const_reverse_iterator critr_t
 

Protected Attributes

task_list_t m_task_set
 
join_type m_join
 
- Protected Attributes inherited from PTL::VTaskGroup
uintmax_t m_id
 
ThreadPoolm_pool
 
std::shared_ptr< atomic_intm_tot_task_count = std::make_shared<atomic_int>(0)
 
std::shared_ptr< condition_tm_task_cond = std::make_shared<condition_t>()
 
std::shared_ptr< lock_tm_task_lock = std::make_shared<lock_t>()
 
tid_type m_main_tid
 
vtask_list_type vtask_list
 

Additional Inherited Members

- Static Public Member Functions inherited from PTL::VTaskGroup
static void set_verbose (int level)
 
- Public Attributes inherited from PTL::TaskAllocatorImpl< Type >
TaskAllocatorPool mem
 
- Protected Member Functions inherited from PTL::VTaskGroup
atomic_inttask_count ()
 
const atomic_inttask_count () const
 
- Static Protected Member Functions inherited from PTL::VTaskGroup
static tid_type this_tid ()
 
- Static Protected Attributes inherited from PTL::VTaskGroup
static int f_verbose = GetEnv<int>("PTL_VERBOSE", 0)
 

Detailed Description

template<typename Tp, typename Arg = Tp>
class PTL::TaskGroup< Tp, Arg >

Definition at line 141 of file TaskGroup.hh.

Member Typedef Documentation

◆ ArgTp

template<typename Tp , typename Arg = Tp>
typedef decay_t<Arg> PTL::TaskGroup< Tp, Arg >::ArgTp

Definition at line 147 of file TaskGroup.hh.

◆ citr_t

template<typename Tp , typename Arg = Tp>
typedef const_iterator PTL::TaskGroup< Tp, Arg >::citr_t
protected

Definition at line 246 of file TaskGroup.hh.

◆ const_iterator

template<typename Tp , typename Arg = Tp>
typedef task_list_t::const_iterator PTL::TaskGroup< Tp, Arg >::const_iterator

Definition at line 157 of file TaskGroup.hh.

◆ const_reverse_iterator

template<typename Tp , typename Arg = Tp>
typedef task_list_t::const_reverse_iterator PTL::TaskGroup< Tp, Arg >::const_reverse_iterator

Definition at line 158 of file TaskGroup.hh.

◆ critr_t

template<typename Tp , typename Arg = Tp>
typedef const_reverse_iterator PTL::TaskGroup< Tp, Arg >::critr_t
protected

Definition at line 248 of file TaskGroup.hh.

◆ future_type

template<typename Tp , typename Arg = Tp>
typedef std::future<ArgTp> PTL::TaskGroup< Tp, Arg >::future_type

Definition at line 151 of file TaskGroup.hh.

◆ iterator

template<typename Tp , typename Arg = Tp>
typedef task_list_t::iterator PTL::TaskGroup< Tp, Arg >::iterator

Definition at line 155 of file TaskGroup.hh.

◆ itr_t

template<typename Tp , typename Arg = Tp>
typedef iterator PTL::TaskGroup< Tp, Arg >::itr_t
protected

Definition at line 245 of file TaskGroup.hh.

◆ join_type

template<typename Tp , typename Arg = Tp>
typedef JoinFunction<Tp,Arg>::Type PTL::TaskGroup< Tp, Arg >::join_type

Definition at line 154 of file TaskGroup.hh.

◆ packaged_task_type

template<typename Tp , typename Arg = Tp>
typedef std::packaged_task<ArgTp()> PTL::TaskGroup< Tp, Arg >::packaged_task_type

Definition at line 152 of file TaskGroup.hh.

◆ promise_type

template<typename Tp , typename Arg = Tp>
typedef std::promise<ArgTp> PTL::TaskGroup< Tp, Arg >::promise_type

Definition at line 150 of file TaskGroup.hh.

◆ result_type

template<typename Tp , typename Arg = Tp>
typedef Tp PTL::TaskGroup< Tp, Arg >::result_type

Definition at line 148 of file TaskGroup.hh.

◆ reverse_iterator

template<typename Tp , typename Arg = Tp>
typedef task_list_t::reverse_iterator PTL::TaskGroup< Tp, Arg >::reverse_iterator

Definition at line 156 of file TaskGroup.hh.

◆ ritr_t

template<typename Tp , typename Arg = Tp>
typedef reverse_iterator PTL::TaskGroup< Tp, Arg >::ritr_t
protected

Definition at line 247 of file TaskGroup.hh.

◆ task_list_t

template<typename Tp , typename Arg = Tp>
typedef list_type<future_type> PTL::TaskGroup< Tp, Arg >::task_list_t

Definition at line 153 of file TaskGroup.hh.

◆ task_type

template<typename Tp , typename Arg = Tp>
template<typename... Args>
using PTL::TaskGroup< Tp, Arg >::task_type = Task<ArgTp, decay_t<Args>...>

Definition at line 161 of file TaskGroup.hh.

◆ this_type

template<typename Tp , typename Arg = Tp>
typedef TaskGroup<Tp, Arg> PTL::TaskGroup< Tp, Arg >::this_type

Definition at line 149 of file TaskGroup.hh.

Constructor & Destructor Documentation

◆ TaskGroup() [1/4]

template<typename Tp , typename Arg = Tp>
template<typename Func >
PTL::TaskGroup< Tp, Arg >::TaskGroup ( Func &&  _join,
ThreadPool _tp = nullptr 
)
inline

Definition at line 167 of file TaskGroup.hh.

168 : VTaskGroup(_tp)
169 , m_join(std::forward<Func>(_join))
170 {}
join_type m_join
Definition: TaskGroup.hh:322
VTaskGroup(ThreadPool *tp=nullptr)
Definition: VTaskGroup.cc:56

◆ TaskGroup() [2/4]

template<typename Tp , typename Arg = Tp>
template<typename Up = Tp, enable_if_t< std::is_same< Up, void >::value, int > = 0>
PTL::TaskGroup< Tp, Arg >::TaskGroup ( ThreadPool _tp = nullptr)
inlineexplicit

Definition at line 172 of file TaskGroup.hh.

173 : VTaskGroup(_tp)
174 , m_join([]() {})
175 {}

◆ ~TaskGroup()

template<typename Tp , typename Arg = Tp>
virtual PTL::TaskGroup< Tp, Arg >::~TaskGroup ( )
inlinevirtual

Definition at line 177 of file TaskGroup.hh.

177{ this->clear(); }

◆ TaskGroup() [3/4]

template<typename Tp , typename Arg = Tp>
PTL::TaskGroup< Tp, Arg >::TaskGroup ( const this_type )
delete

◆ TaskGroup() [4/4]

template<typename Tp , typename Arg = Tp>
PTL::TaskGroup< Tp, Arg >::TaskGroup ( this_type &&  rhs)
default

Member Function Documentation

◆ begin() [1/2]

template<typename Tp , typename Arg = Tp>
itr_t PTL::TaskGroup< Tp, Arg >::begin ( )
inline

Definition at line 260 of file TaskGroup.hh.

260{ return m_task_set.begin(); }
task_list_t m_task_set
Definition: TaskGroup.hh:321

◆ begin() [2/2]

template<typename Tp , typename Arg = Tp>
citr_t PTL::TaskGroup< Tp, Arg >::begin ( ) const
inline

Definition at line 262 of file TaskGroup.hh.

262{ return m_task_set.begin(); }

◆ cbegin()

template<typename Tp , typename Arg = Tp>
citr_t PTL::TaskGroup< Tp, Arg >::cbegin ( ) const
inline

Definition at line 264 of file TaskGroup.hh.

264{ return m_task_set.begin(); }

◆ cend()

template<typename Tp , typename Arg = Tp>
citr_t PTL::TaskGroup< Tp, Arg >::cend ( ) const
inline

Definition at line 265 of file TaskGroup.hh.

265{ return m_task_set.end(); }

◆ clear()

template<typename Tp , typename Arg = Tp>
void PTL::TaskGroup< Tp, Arg >::clear ( )
inline

Definition at line 313 of file TaskGroup.hh.

314 {
315 m_task_set.clear();
317 }

Referenced by PTL::TaskGroup< Tp, Arg >::join(), and PTL::TaskGroup< Tp, Arg >::~TaskGroup().

◆ end() [1/2]

template<typename Tp , typename Arg = Tp>
itr_t PTL::TaskGroup< Tp, Arg >::end ( )
inline

Definition at line 261 of file TaskGroup.hh.

261{ return m_task_set.end(); }

◆ end() [2/2]

template<typename Tp , typename Arg = Tp>
citr_t PTL::TaskGroup< Tp, Arg >::end ( ) const
inline

Definition at line 263 of file TaskGroup.hh.

263{ return m_task_set.end(); }

◆ exec()

template<typename Tp , typename Arg = Tp>
template<typename Func , typename... Args>
void PTL::TaskGroup< Tp, Arg >::exec ( Func &&  func,
Args...  args 
)
inline

Definition at line 215 of file TaskGroup.hh.

216 {
217 m_pool->add_task(wrap(std::forward<Func>(func), args...));
218 }
task_type< Args... > * wrap(Func &&func, Args... args)
Definition: TaskGroup.hh:206
size_type add_task(task_pointer task, int bin=-1)
Definition: ThreadPool.hh:328
ThreadPool * m_pool
Definition: VTaskGroup.hh:136

Referenced by G4TaskRunManager::AddEventTask(), PTL::TaskManager::exec(), and PTL::TaskManager::rexec().

◆ get_tasks() [1/2]

template<typename Tp , typename Arg = Tp>
task_list_t & PTL::TaskGroup< Tp, Arg >::get_tasks ( )
inline

Definition at line 254 of file TaskGroup.hh.

254{ return m_task_set; }

◆ get_tasks() [2/2]

template<typename Tp , typename Arg = Tp>
const task_list_t & PTL::TaskGroup< Tp, Arg >::get_tasks ( ) const
inline

Definition at line 255 of file TaskGroup.hh.

255{ return m_task_set; }

◆ join() [1/3]

template<typename Tp , typename Arg = Tp>
template<typename Up = Tp, typename Rp = Arg, enable_if_t< std::is_void< Up >::value &&std::is_void< Rp >::value, int > = 0>
void PTL::TaskGroup< Tp, Arg >::join ( )
inline

Definition at line 289 of file TaskGroup.hh.

290 {
291 this->wait();
292 for(auto& itr : m_task_set)
293 itr.get();
294 m_join();
295 this->clear();
296 }
virtual void wait()
Definition: VTaskGroup.cc:81

◆ join() [2/3]

template<typename Tp , typename Arg = Tp>
template<typename Up = Tp, typename Rp = Arg, enable_if_t< std::is_void< Up >::value &&!std::is_void< Rp >::value, int > = 0>
void PTL::TaskGroup< Tp, Arg >::join ( )
inline

Definition at line 301 of file TaskGroup.hh.

302 {
303 this->wait();
304 for(auto& itr : m_task_set)
305 {
306 using RetT = decay_t<decltype(itr.get())>;
307 m_join(std::forward<RetT>(itr.get()));
308 }
309 this->clear();
310 }
typename std::decay< T >::type decay_t
Definition: Globals.hh:52

◆ join() [3/3]

template<typename Tp , typename Arg = Tp>
template<typename Up = Tp, enable_if_t<!std::is_void< Up >::value, int > = 0>
Up PTL::TaskGroup< Tp, Arg >::join ( Up  accum = {})
inline

Definition at line 274 of file TaskGroup.hh.

274 {})
275 {
276 this->wait();
277 for(auto& itr : m_task_set)
278 {
279 using RetT = decay_t<decltype(itr.get())>;
280 accum = std::move(m_join(std::ref(accum), std::forward<RetT>(itr.get())));
281 }
282 this->clear();
283 return accum;
284 }

Referenced by G4TaskRunManager::TerminateWorkers(), G4TaskRunManager::WaitForEndEventLoopWorkers(), and G4TaskRunManager::~G4TaskRunManager().

◆ operator+=()

template<typename Tp , typename Arg = Tp>
template<typename Up >
Up * PTL::TaskGroup< Tp, Arg >::operator+= ( Up *  _task)
inline

Definition at line 191 of file TaskGroup.hh.

192 {
193 // store in list
194 vtask_list.push_back(_task);
195 // thread-safe increment of tasks in task group
196 operator++();
197 // add the future
198 m_task_set.push_back(std::move(_task->get_future()));
199 // return
200 return _task;
201 }
vtask_list_type vtask_list
Definition: VTaskGroup.hh:141
intmax_t operator++()
Definition: VTaskGroup.hh:92

Referenced by PTL::TaskGroup< Tp, Arg >::wrap().

◆ operator=() [1/2]

template<typename Tp , typename Arg = Tp>
this_type & PTL::TaskGroup< Tp, Arg >::operator= ( const this_type rhs)
delete

◆ operator=() [2/2]

template<typename Tp , typename Arg = Tp>
this_type & PTL::TaskGroup< Tp, Arg >::operator= ( this_type &&  rhs)
default

◆ parallel_for()

template<typename Tp , typename Arg = Tp>
template<typename Func , typename... Args>
void PTL::TaskGroup< Tp, Arg >::parallel_for ( const intmax_t &  nitr,
const intmax_t &  chunks,
Func &&  func,
Args...  args 
)
inline

Definition at line 227 of file TaskGroup.hh.

229 {
230 auto nsplit = nitr / chunks;
231 auto nmod = nitr % chunks;
232 if(nsplit < 1)
233 nsplit = 1;
234 for(intmax_t n = 0; n < nsplit; ++n)
235 {
236 auto _beg = n * chunks;
237 auto _end = (n + 1) * chunks + ((n + 1 == nsplit) ? nmod : 0);
238 run(std::forward<Func>(func), std::move(_beg), std::move(_end), args...);
239 }
240 }
void run(Func &&func, Args... args)
Definition: TaskGroup.hh:221

◆ rbegin() [1/2]

template<typename Tp , typename Arg = Tp>
ritr_t PTL::TaskGroup< Tp, Arg >::rbegin ( )
inline

Definition at line 266 of file TaskGroup.hh.

266{ return m_task_set.rbegin(); }

◆ rbegin() [2/2]

template<typename Tp , typename Arg = Tp>
critr_t PTL::TaskGroup< Tp, Arg >::rbegin ( ) const
inline

Definition at line 268 of file TaskGroup.hh.

268{ return m_task_set.rbegin(); }

◆ rend() [1/2]

template<typename Tp , typename Arg = Tp>
ritr_t PTL::TaskGroup< Tp, Arg >::rend ( )
inline

Definition at line 267 of file TaskGroup.hh.

267{ return m_task_set.rend(); }

◆ rend() [2/2]

template<typename Tp , typename Arg = Tp>
critr_t PTL::TaskGroup< Tp, Arg >::rend ( ) const
inline

Definition at line 269 of file TaskGroup.hh.

269{ return m_task_set.rend(); }

◆ run()

template<typename Tp , typename Arg = Tp>
template<typename Func , typename... Args>
void PTL::TaskGroup< Tp, Arg >::run ( Func &&  func,
Args...  args 
)
inline

Definition at line 221 of file TaskGroup.hh.

222 {
223 m_pool->add_task(wrap(std::forward<Func>(func), args...));
224 }

Referenced by PTL::TaskGroup< Tp, Arg >::parallel_for().

◆ wrap()

template<typename Tp , typename Arg = Tp>
template<typename Func , typename... Args>
task_type< Args... > * PTL::TaskGroup< Tp, Arg >::wrap ( Func &&  func,
Args...  args 
)
inline

Definition at line 206 of file TaskGroup.hh.

207 {
208 return operator+=(
209 new task_type<Args...>(this, std::forward<Func>(func), args...));
210 }
Up * operator+=(Up *_task)
Definition: TaskGroup.hh:191

Referenced by PTL::TaskGroup< Tp, Arg >::exec(), PTL::TaskGroup< Tp, Arg >::run(), and PTL::TaskManager::wrap().

Member Data Documentation

◆ m_join

template<typename Tp , typename Arg = Tp>
join_type PTL::TaskGroup< Tp, Arg >::m_join
protected

Definition at line 322 of file TaskGroup.hh.

Referenced by PTL::TaskGroup< Tp, Arg >::join().

◆ m_task_set


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