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

#include <VUserTaskQueue.hh>

+ Inheritance diagram for PTL::VUserTaskQueue:

Public Types

typedef VTasktask_pointer
 
typedef std::atomic< intmax_t > AtomicInt
 
typedef uintmax_t size_type
 
typedef std::function< void()> function_type
 
typedef std::set< ThreadIdThreadIdSet
 

Public Member Functions

 VUserTaskQueue (intmax_t nworkers=-1)
 
virtual ~VUserTaskQueue ()
 
virtual task_pointer GetTask (intmax_t subq=-1, intmax_t nitr=-1)=0
 
virtual intmax_t InsertTask (task_pointer, ThreadData *=nullptr, intmax_t subq=-1)=0
 
virtual void Wait ()=0
 
virtual intmax_t GetThreadBin () const =0
 
virtual void resize (intmax_t)=0
 
virtual size_type size () const =0
 
virtual bool empty () const =0
 
virtual size_type bin_size (size_type bin) const =0
 
virtual bool bin_empty (size_type bin) const =0
 
virtual size_type true_size () const
 
virtual bool true_empty () const
 
virtual void ExecuteOnAllThreads (ThreadPool *tp, function_type f)=0
 
virtual void ExecuteOnSpecificThreads (ThreadIdSet tid_set, ThreadPool *tp, function_type f)=0
 
intmax_t workers () const
 
virtual VUserTaskQueueclone ()=0
 

Static Public Member Functions

template<typename ContainerT , size_t... Idx>
static auto ContainerToTupleImpl (ContainerT &&container, mpl::index_sequence< Idx... >) -> decltype(std::make_tuple(std::forward< ContainerT >(container)[Idx]...))
 
template<std::size_t N, typename ContainerT >
static auto ContainerToTuple (ContainerT &&container) -> decltype(ContainerToTupleImpl(std::forward< ContainerT >(container), mpl::make_index_sequence< N >{}))
 
template<std::size_t N, std::size_t Nt, typename TupleT , enable_if_t<(N==Nt), int > = 0>
static void TExecutor (TupleT &&_t)
 
template<std::size_t N, std::size_t Nt, typename TupleT , enable_if_t<(N< Nt), int > = 0>
static void TExecutor (TupleT &&_t)
 
template<typename TupleT , std::size_t N = std::tuple_size<decay_t<TupleT>>::value>
static void Executor (TupleT &&__t)
 
template<typename Container , typename std::enable_if< std::is_same< Container, task_pointer >::value, int >::type = 0>
static void Execute (Container &obj)
 
template<typename Container , typename std::enable_if<!std::is_same< Container, task_pointer >::value, int >::type = 0>
static void Execute (Container &tasks)
 

Protected Attributes

intmax_t m_workers = 0
 

Detailed Description

Definition at line 47 of file VUserTaskQueue.hh.

Member Typedef Documentation

◆ AtomicInt

typedef std::atomic<intmax_t> PTL::VUserTaskQueue::AtomicInt

Definition at line 51 of file VUserTaskQueue.hh.

◆ function_type

typedef std::function<void()> PTL::VUserTaskQueue::function_type

Definition at line 53 of file VUserTaskQueue.hh.

◆ size_type

typedef uintmax_t PTL::VUserTaskQueue::size_type

Definition at line 52 of file VUserTaskQueue.hh.

◆ task_pointer

Definition at line 50 of file VUserTaskQueue.hh.

◆ ThreadIdSet

Definition at line 54 of file VUserTaskQueue.hh.

Constructor & Destructor Documentation

◆ VUserTaskQueue()

VUserTaskQueue::VUserTaskQueue ( intmax_t  nworkers = -1)
explicit

Definition at line 35 of file VUserTaskQueue.cc.

36: m_workers(nworkers)
37{
38 if(m_workers < 0)
39 {
41 m_workers = (rm) ? rm->GetNumberOfThreads() + 1 // number of threads + 1
42 : (2 * std::thread::hardware_concurrency()) + 1;
43 // hyperthreads + 1
44 }
45}
virtual int GetNumberOfThreads() const
static TaskRunManager * GetMasterRunManager(bool useTBB=false)

◆ ~VUserTaskQueue()

VUserTaskQueue::~VUserTaskQueue ( )
virtual

Definition at line 49 of file VUserTaskQueue.cc.

49{}

Member Function Documentation

◆ bin_empty()

virtual bool PTL::VUserTaskQueue::bin_empty ( size_type  bin) const
pure virtual

Implemented in PTL::UserTaskQueue.

◆ bin_size()

virtual size_type PTL::VUserTaskQueue::bin_size ( size_type  bin) const
pure virtual

Implemented in PTL::UserTaskQueue.

◆ clone()

virtual VUserTaskQueue * PTL::VUserTaskQueue::clone ( )
pure virtual

Implemented in PTL::UserTaskQueue.

◆ ContainerToTuple()

template<std::size_t N, typename ContainerT >
static auto PTL::VUserTaskQueue::ContainerToTuple ( ContainerT &&  container) -> decltype(ContainerToTupleImpl(std::forward<ContainerT>(container), mpl::make_index_sequence<N>{}))
inlinestatic

Definition at line 125 of file VUserTaskQueue.hh.

127 {}))
128 {
129 return ContainerToTupleImpl(std::forward<ContainerT>(container),
130 mpl::make_index_sequence<N>{});
131 }
static auto ContainerToTupleImpl(ContainerT &&container, mpl::index_sequence< Idx... >) -> decltype(std::make_tuple(std::forward< ContainerT >(container)[Idx]...))

◆ ContainerToTupleImpl()

template<typename ContainerT , size_t... Idx>
static auto PTL::VUserTaskQueue::ContainerToTupleImpl ( ContainerT &&  container,
mpl::index_sequence< Idx... >   
) -> decltype(std::make_tuple(std::forward<ContainerT>(container)[Idx]...))
inlinestatic

Definition at line 118 of file VUserTaskQueue.hh.

120 {
121 return std::make_tuple(std::forward<ContainerT>(container)[Idx]...);
122 }

◆ empty()

virtual bool PTL::VUserTaskQueue::empty ( ) const
pure virtual

◆ Execute() [1/2]

template<typename Container , typename std::enable_if< std::is_same< Container, task_pointer >::value, int >::type = 0>
static void PTL::VUserTaskQueue::Execute ( Container &  obj)
inlinestatic

Definition at line 159 of file VUserTaskQueue.hh.

160 {
161 if(obj.get())
162 (*obj)();
163 }

◆ Execute() [2/2]

template<typename Container , typename std::enable_if<!std::is_same< Container, task_pointer >::value, int >::type = 0>
static void PTL::VUserTaskQueue::Execute ( Container &  tasks)
inlinestatic

Definition at line 168 of file VUserTaskQueue.hh.

169 {
170 /*
171 for(auto& itr : tasks)
172 {
173 if(itr.get())
174 (*itr)();
175 }*/
176
177 size_type n = tasks.size();
178 size_type max_n = 4;
179 while(n > 0)
180 {
181 auto compute = (n > max_n) ? max_n : n;
182 switch(compute)
183 {
184 case 4: {
185 auto t = ContainerToTuple<4>(tasks);
186 Executor(t);
187 break;
188 }
189 case 3: {
190 auto t = ContainerToTuple<3>(tasks);
191 Executor(t);
192 break;
193 }
194 case 2: {
195 auto t = ContainerToTuple<2>(tasks);
196 Executor(t);
197 break;
198 }
199 case 1: {
200 auto t = ContainerToTuple<1>(tasks);
201 Executor(t);
202 break;
203 }
204 case 0: break;
205 }
206 // tasks.erase(tasks.begin(), tasks.begin() + compute);
207 n -= compute;
208 }
209 }
static void Executor(TupleT &&__t)

◆ ExecuteOnAllThreads()

virtual void PTL::VUserTaskQueue::ExecuteOnAllThreads ( ThreadPool tp,
function_type  f 
)
pure virtual

◆ ExecuteOnSpecificThreads()

virtual void PTL::VUserTaskQueue::ExecuteOnSpecificThreads ( ThreadIdSet  tid_set,
ThreadPool tp,
function_type  f 
)
pure virtual

Implemented in PTL::UserTaskQueue.

◆ Executor()

template<typename TupleT , std::size_t N = std::tuple_size<decay_t<TupleT>>::value>
static void PTL::VUserTaskQueue::Executor ( TupleT &&  __t)
inlinestatic

Definition at line 151 of file VUserTaskQueue.hh.

152 {
153 TExecutor<0, N - 1, TupleT>(std::forward<TupleT>(__t));
154 }
static void TExecutor(TupleT &&_t)

Referenced by Execute().

◆ GetTask()

virtual task_pointer PTL::VUserTaskQueue::GetTask ( intmax_t  subq = -1,
intmax_t  nitr = -1 
)
pure virtual

Implemented in PTL::UserTaskQueue.

Referenced by PTL::ThreadPool::execute_thread().

◆ GetThreadBin()

virtual intmax_t PTL::VUserTaskQueue::GetThreadBin ( ) const
pure virtual

Implemented in PTL::UserTaskQueue.

◆ InsertTask()

virtual intmax_t PTL::VUserTaskQueue::InsertTask ( task_pointer  ,
ThreadData = nullptr,
intmax_t  subq = -1 
)
pure virtual

◆ resize()

virtual void PTL::VUserTaskQueue::resize ( intmax_t  )
pure virtual

Implemented in PTL::UserTaskQueue.

Referenced by PTL::ThreadPool::resize().

◆ size()

virtual size_type PTL::VUserTaskQueue::size ( ) const
pure virtual

Implemented in PTL::UserTaskQueue.

Referenced by true_size().

◆ TExecutor() [1/2]

template<std::size_t N, std::size_t Nt, typename TupleT , enable_if_t<(N==Nt), int > = 0>
static void PTL::VUserTaskQueue::TExecutor ( TupleT &&  _t)
inlinestatic

Definition at line 135 of file VUserTaskQueue.hh.

136 {
137 if(std::get<N>(_t).get())
138 (*(std::get<N>(_t)))();
139 }
auto get(Tuple< Elements... > &t) -> decltype(get_height< sizeof...(Elements) - I - 1 >(t))
Definition: Tuple.hh:139

Referenced by Executor().

◆ TExecutor() [2/2]

template<std::size_t N, std::size_t Nt, typename TupleT , enable_if_t<(N< Nt), int > = 0>
static void PTL::VUserTaskQueue::TExecutor ( TupleT &&  _t)
inlinestatic

Definition at line 143 of file VUserTaskQueue.hh.

144 {
145 if(std::get<N>(_t).get())
146 (*(std::get<N>(_t)))();
147 TExecutor<N + 1, Nt, TupleT>(std::forward<TupleT>(_t));
148 }

◆ true_empty()

virtual bool PTL::VUserTaskQueue::true_empty ( ) const
inlinevirtual

Reimplemented in PTL::UserTaskQueue.

Definition at line 96 of file VUserTaskQueue.hh.

96{ return empty(); }
virtual bool empty() const =0

◆ true_size()

virtual size_type PTL::VUserTaskQueue::true_size ( ) const
inlinevirtual

Reimplemented in PTL::UserTaskQueue.

Definition at line 95 of file VUserTaskQueue.hh.

95{ return size(); }
virtual size_type size() const =0

Referenced by PTL::ThreadPool::execute_thread().

◆ Wait()

virtual void PTL::VUserTaskQueue::Wait ( )
pure virtual

Implemented in PTL::UserTaskQueue.

◆ workers()

intmax_t PTL::VUserTaskQueue::workers ( ) const
inline

Definition at line 104 of file VUserTaskQueue.hh.

104{ return m_workers; }

Referenced by PTL::UserTaskQueue::clone().

Member Data Documentation

◆ m_workers


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