Helios++
Helios software for LiDAR simulations
PulseThreadPool Class Reference

Class implementing a thread pool to deal with pulse tasks. More...

#include <PulseThreadPool.h>

Inheritance diagram for PulseThreadPool:
Collaboration diagram for PulseThreadPool:

Public Member Functions

 PulseThreadPool (std::size_t const _pool_size, double const deviceAccuracy, bool const dynamic)
 Pulse thread pool constructor. More...
 
void run_pulse_task (TaskDropper< PulseTask, PulseThreadPoolInterface, std::vector< std::vector< double >> &, RandomnessGenerator< double > &, RandomnessGenerator< double > &, NoiseSource< double > & > &dropper) override
 
bool try_run_pulse_task (TaskDropper< PulseTask, PulseThreadPoolInterface, std::vector< std::vector< double >> &, RandomnessGenerator< double > &, RandomnessGenerator< double > &, NoiseSource< double > & > &dropper) override
 
void join () override
 
virtual bool isDynamic () const
 Check if the pulse thread pool is operating on dynamic mode (true) or not (false) More...
 
- Public Member Functions inherited from ResThreadPool< std::vector< std::vector< double > > &, RandomnessGenerator< double > &, RandomnessGenerator< double > &, NoiseSource< double > & >
 ResThreadPool (std::size_t const _pool_size)
 Resource thread pool constructor. More...
 
void run_res_task (Task task)
 Run a task with associated resources when there is an available thread for it.
 
bool try_run_res_task (Task task)
 Run a task with associated resources. If there is not even a single available thread, then return false so non-blocking behavior is possible. More...
 
- Public Member Functions inherited from SimpleThreadPool< TaskArgs ... >
 SimpleThreadPool (std::size_t const _pool_size)
 Simple thread pool constructor. More...
 
void run_task (Task task)
 Run a task when there is an available thread for it.
 
virtual void notifyOne ()
 Notify the conditional variable so if there is a waiting thread it will wake up.
 
- Public Member Functions inherited from ThreadPool
 ThreadPool (std::size_t const _pool_size)
 Thread pool constructor. More...
 
virtual std::size_t getPoolSize () const
 Obtain the thread pool size. More...
 

Public Attributes

TimeWatcher idleTimer
 Time watcher to count the amount of idle time. More...
 
bool dynamic
 Specify whether the pulse thread pool uses a dynamic chunk size strategy (true) or a static one (false)
 

Protected Member Functions

void do_res_task (boost::function< void(std::vector< std::vector< double >> &, RandomnessGenerator< double > &, RandomnessGenerator< double > &, NoiseSource< double > &)> &task, int const resourceIdx) override
 Do a pulse task. More...
 
void wrap_res_task (boost::function< void(std::vector< std::vector< double >> &, RandomnessGenerator< double > &, RandomnessGenerator< double > &, NoiseSource< double > &)> &task, int const resourceIdx) override
 Override task wrapping so when the full thread group is used the time at which first occupied thread becomes available is registered. More...
 
- Protected Member Functions inherited from ResThreadPool< std::vector< std::vector< double > > &, RandomnessGenerator< double > &, RandomnessGenerator< double > &, NoiseSource< double > & >
virtual int getAvailableResourceSetIndex () const
 Obtain the index of an available resource set. More...
 
virtual void wrap_res_task (boost::function< void(TaskArgs ...)> &task, int const resourceIdx)
 Wrap a task so that available threads count can be increased once provided task has been completed. More...
 
void do_task (boost::function< void(TaskArgs ...)> &task) override
 Throw exception when calling non resource do_task. More...
 
virtual void do_res_task (boost::function< void(TaskArgs ...)> &task, int const resourceIdx)=0
 Invoke task with associated resources with corresponding arguments. More...
 
- Protected Member Functions inherited from SimpleThreadPool< TaskArgs ... >
virtual void wrap_task (boost::function< void(TaskArgs ...)> &task)
 Wrap a task so that available threads count can be increased once provided task has been completed. More...
 

Protected Attributes

std::vector< std::vector< double > > * apMatrices
 
RandomnessGenerator< double > * randGens
 First randomness generators (general purpose), one per thread.
 
RandomnessGenerator< double > * randGens2
 Second randomness generators (to substitute old box muller), one per thread.
 
UniformNoiseSource< double > * intersectionHandlingNoiseSources
 Intersection handling noise sources, one per thread.
 
- Protected Attributes inherited from ResThreadPool< std::vector< std::vector< double > > &, RandomnessGenerator< double > &, RandomnessGenerator< double > &, NoiseSource< double > & >
bool * resourceSetAvailable
 Array of flags specifying availability of resource sets. More...
 
- Protected Attributes inherited from SimpleThreadPool< TaskArgs ... >
std::size_t available_
 Number of available threads, those which are not currently performing a task.
 
boost::mutex mutex_
 Mutex to handle concurrent tasks.
 
boost::condition_variable cond_
 Condition variable to handle tasks dispatching depending on available threads.
 
boost::asio::io_service io_service_
 Instance of boost input/output service for asynchronous data processing.
 
std::size_t pool_size
 Size of thread pool (number of threads)
 
- Protected Attributes inherited from ThreadPool
boost::asio::io_service io_service_
 Instance of boost input/output service for asynchronous data processing.
 
boost::asio::executor_work_guard< boost::asio::io_service::executor_type > work_
 Instance of work guard to report the io service when it has pending tasks. More...
 
std::size_t pool_size
 Size of thread pool (number of threads)
 
boost::thread_group threads_
 Group of threads.
 

Detailed Description

Class implementing a thread pool to deal with pulse tasks.

Version
1.0
See also
ResThreadPool

Constructor & Destructor Documentation

◆ PulseThreadPool()

PulseThreadPool::PulseThreadPool ( std::size_t const  _pool_size,
double const  deviceAccuracy,
bool const  dynamic 
)
inlineexplicit

Pulse thread pool constructor.

See also
ThreadPool::pool_size
Parameters
deviceAccuracyParameter used to handle randomness generation impact on simulation results

Member Function Documentation

◆ do_res_task()

void PulseThreadPool::do_res_task ( boost::function< void(std::vector< std::vector< double >> &, RandomnessGenerator< double > &, RandomnessGenerator< double > &, NoiseSource< double > &)> &  task,
int const  resourceIdx 
)
inlineoverrideprotected

Do a pulse task.

Parameters
taskPulse task
See also
ResThreadPool::do_task

◆ isDynamic()

virtual bool PulseThreadPool::isDynamic ( ) const
inlinevirtual

Check if the pulse thread pool is operating on dynamic mode (true) or not (false)

Returns
True if dynamic chunk scheduling, false if static

◆ join()

void PulseThreadPool::join ( )
inlineoverridevirtual

◆ run_pulse_task()

void PulseThreadPool::run_pulse_task ( TaskDropper< PulseTask, PulseThreadPoolInterface, std::vector< std::vector< double >> &, RandomnessGenerator< double > &, RandomnessGenerator< double > &, NoiseSource< double > & > &  dropper)
inlineoverridevirtual

◆ try_run_pulse_task()

bool PulseThreadPool::try_run_pulse_task ( TaskDropper< PulseTask, PulseThreadPoolInterface, std::vector< std::vector< double >> &, RandomnessGenerator< double > &, RandomnessGenerator< double > &, NoiseSource< double > & > &  dropper)
inlineoverridevirtual

◆ wrap_res_task()

void PulseThreadPool::wrap_res_task ( boost::function< void(std::vector< std::vector< double >> &, RandomnessGenerator< double > &, RandomnessGenerator< double > &, NoiseSource< double > &)> &  task,
int const  resourceIdx 
)
inlineoverrideprotected

Override task wrapping so when the full thread group is used the time at which first occupied thread becomes available is registered.

See also
PulseThreadPool::firstAvailableTime

Member Data Documentation

◆ apMatrices

std::vector<std::vector<double> >* PulseThreadPool::apMatrices
protected

Alpha prime matrices for MarquardtFitter. One per possible thread, to avoid spamming reallocations

◆ idleTimer

TimeWatcher PulseThreadPool::idleTimer

Time watcher to count the amount of idle time.

It is started when all threads are occupied as soon as the first thread becomes available (finishes its job). It must stopped by the asynchronous process at the correct point. This means the idle timer is meant to be used with non-blocking task posting, it is when using ResThreadPool::try_run_res_task method instead of ResThreadPool::run_res_task

See also
ResThreadPool::try_run_res_task

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