49 "Threading using Boost.");
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: " << e.what()
85 cerr <<
"Exception while allocating worker threads: " << e.what()
102 std::cerr <<
"Exception while creating worker threads" << std::endl;
109 m_type =
"Threading with Boost";
146 std::vector<ThreadJob *>::iterator it;
147 for (it = joblist.begin(); it < joblist.end(); ++it)
168 bool working =
false;
200 boost::thread::id
id = boost::this_thread::get_id();
236 boost::thread::id
id = boost::this_thread::get_id();
253 m_barrier =
new boost::barrier(num > 0 ? num : 1);
270 n = std::max(n,
static_cast<unsigned int>(0));
314 unsigned int workerNum)
315 : m_threadManager(tm), m_workerQueue(), m_keepgoing(true),
316 m_threadNum(workerNum)
328 std::cerr <<
"Warning: ThreadWorker: " <<
m_threadNum
329 <<
"destroyed while running!" << std::endl;
374 unsigned int numToLoad = 0;
378 numToLoad = std::max(
380 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
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.
std::queue< ThreadJob * > m_masterQueue
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.