25 #ifndef WTHREADEDJOBS_H
26 #define WTHREADEDJOBS_H
32 #include "WException.h"
49 template<
class Input_T,
class Job_T >
95 virtual void compute( std::shared_ptr< InputType const > input,
JobType const& job ) = 0;
99 std::shared_ptr< InputType const >
m_input;
103 template<
class Input_T,
class Job_T >
109 throw WException( std::string(
"Invalid input." ) );
113 template<
class Input_T,
class Job_T >
118 template<
class Input_T,
class Job_T >
122 while( getJob( job ) && !shutdown() )
124 compute( m_input, job );
132 template<
class Input_T,
class Job_T >
170 virtual void compute( std::shared_ptr< InputType const > input, std::size_t voxelNum ) = 0;
178 template<
class Input_T,
class Job_T >
184 throw WException( std::string(
"Invalid input." ) );
188 template<
class Input_T,
class Job_T >
193 template<
class Input_T,
class Job_T >
196 WAssert( m_input,
"Bug: operations of an invalid input requested." );
197 size_t numElements = m_input->size();
200 size_t start = numElements / numThreads * id;
201 size_t end = (
id + 1 ) * ( numElements / numThreads );
202 if(
id == numThreads - 1 )
207 for(
size_t voxelNum = start; ( voxelNum < end ) && !shutdown(); ++voxelNum )
209 compute( m_input, voxelNum );
A threaded functor base class for producer-consumer-style multithreaded computation.
std::shared_ptr< InputType const > m_input
the input
virtual ~WThreadedJobs()
Destructor.
void operator()(std::size_t id, std::size_t numThreads, WBoolFlag const &shutdown)
The threaded function operation.
WThreadedJobs(std::shared_ptr< InputType const > input)
Constructor.
virtual bool getJob(JobType &job)=0
Abstract function for the job aquisition.
virtual void compute(std::shared_ptr< InputType const > input, JobType const &job)=0
Abstract function that performs the actual computation per job.
Input_T InputType
the input type
Job_T JobType
the job type
Nearly the same class as WThreadedJobs, but this class is intended to be used for multithreaded opera...
WThreadedStripingJobs(std::shared_ptr< InputType const > input)
Constructor.
void operator()(std::size_t id, std::size_t numThreads, WBoolFlag const &shutdown)
The threaded function operation.
std::shared_ptr< InputType const > m_input
the input
Input_T InputType
the input type
virtual ~WThreadedStripingJobs()
Destructor.
Job_T JobType
the job type
virtual void compute(std::shared_ptr< InputType const > input, std::size_t voxelNum)=0
Abstract function that performs the actual computation per voxel.