56 m_numThreads(numT), m_numWorkers(numT), m_masterQueue(),
57 m_masterQueueMutex(), m_masterActiveMutex(), m_masterQueueCondVar(),
58 m_masterActiveCondVar(), m_chunkSize(1), m_schedType(
e_dynamic),
71 cerr <<
"Exception while allocating thread storage: "
85 cerr <<
"Exception while allocating worker threads: "
102 std::cerr <<
"Exception while creating worker threads" << std::endl;
109 m_type =
"Threading with Boost";
148 std::vector<ThreadJob *>::iterator it;
149 for (it=joblist.begin(); it<joblist.end(); ++it)
172 bool working =
false;
207 boost::thread::id
id = boost::this_thread::get_id();
246 boost::thread::id
id = boost::this_thread::get_id();
264 m_barrier =
new boost::barrier(num > 0 ? num : 1);
282 n = std::max(n,
static_cast<unsigned int>(0));
332 m_threadManager(tm), m_workerQueue(),
333 m_keepgoing(true), m_threadNum(workerNum)
347 std::cerr <<
"Warning: ThreadWorker: " <<
m_threadNum
348 <<
"destroyed while running!" << std::endl;
396 unsigned int numToLoad = 0;
400 numToLoad = std::max(
402 static_cast<unsigned long>(
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Base class for tasks to be sent to the ThreadManager to run.
void SetWorkerNum(unsigned int num)
Set number of worker threads.
Implementation of ThreadManager using Boost threads.
boost::mutex m_masterQueueMutex
ThreadWorkerBoost ** m_threadList
virtual const std::string & GetType() const
Returns a description of the type of threading.
virtual unsigned int GetWorkerNum()
Returns the worker number of the executing thread.
virtual ~ThreadManagerBoost()
Shuts down threading.
virtual void QueueJob(ThreadJob *job)
Pass a single job to the master queue.
bool * m_threadActiveList
std::queue< ThreadJob * > m_masterQueue
boost::condition_variable m_masterQueueCondVar
virtual bool InThread()
Indicates whether the code is in a worker thread or not.
boost::thread::id m_masterThreadId
const unsigned int m_numThreads
virtual void SetNumWorkers()
Sets the number of active workers to the maximum.
static ThreadManagerSharedPtr Create(unsigned int numT)
Called by the factory method.
virtual void Hold()
A calling threads holds until all active threads call this method.
std::map< boost::thread::id, unsigned int > m_threadMap
virtual unsigned int GetNumWorkers()
Return the number of active workers.
friend class ThreadWorkerBoost
static std::string className
void SetNumWorkersImpl(const unsigned int num)
unsigned int m_numWorkers
boost::barrier * m_barrier
virtual unsigned int GetMaxNumWorkers()
Gets the maximum available number of threads.
boost::thread ** m_threadThreadList
boost::condition_variable m_masterActiveCondVar
virtual void SetChunkSize(unsigned int chnk)
Controls how many jobs are sent to each worker at a time.
virtual void QueueJobs(std::vector< ThreadJob * > &joblist)
Pass a list of tasklets to the master queue.
boost::mutex m_masterActiveMutex
virtual void SetSchedType(SchedType s)
Sets the current scheduling algorithm.
virtual void Wait()
Waits until all queued jobs are finished.
Implementation class for ThreadManagerBoost.
~ThreadWorkerBoost()
Destructor.
void Stop()
A signal to shut down.
std::queue< ThreadJob * > m_workerQueue
unsigned int GetNumToLoad()
ThreadManagerBoost * m_threadManager
SchedType
Identifies the algorithm for scheduling.
ThreadManagerFactory & GetThreadManagerFactory()
boost::unique_lock< boost::mutex > Lock
The above copyright notice and this permission notice shall be included.