57 m_numThreads(numT), m_numWorkers(numT), m_masterQueue(),
58 m_masterQueueMutex(), m_masterActiveMutex(), m_masterQueueCondVar(),
59 m_masterActiveCondVar(), m_chunkSize(1), m_schedType(
e_dynamic),
72 cerr <<
"Exception while allocating thread storage: "
86 cerr <<
"Exception while allocating worker threads: "
103 std::cerr <<
"Exception while creating worker threads" << std::endl;
110 m_type =
"Threading with Boost";
150 for (it=joblist.begin(); it<joblist.end(); ++it)
173 bool working =
false;
208 boost::thread::id
id = boost::this_thread::get_id();
247 boost::thread::id
id = boost::this_thread::get_id();
265 m_barrier =
new boost::barrier(num > 0 ? num : 1);
282 num = std::max(num, 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;
400 numToLoad = std::max(
402 static_cast<unsigned long>(
412 ASSERTL0(0,
"Invalid value for SchedType.");
virtual bool InThread()
Indicates whether the code is in a worker thread or not.
virtual unsigned int GetMaxNumWorkers()
Gets the maximum available number of threads.
ThreadManagerBoost * m_threadManager
boost::thread::id m_masterThreadId
boost::mutex m_masterQueueMutex
#define ASSERTL0(condition, msg)
std::queue< ThreadJob * > m_workerQueue
~ThreadWorkerBoost()
Destructor.
const unsigned int m_numThreads
virtual void Wait()
Waits until all queued jobs are finished.
void SetWorkerNum(unsigned int num)
Set number of worker threads.
virtual const std::string & GetType() const
Returns a description of the type of threading.
virtual void SetSchedType(SchedType s)
Sets the current scheduling algorithm.
friend class ThreadWorkerBoost
virtual unsigned int GetWorkerNum()
Returns the worker number of the executing thread.
boost::condition_variable m_masterQueueCondVar
virtual void QueueJobs(std::vector< ThreadJob * > &joblist)
Pass a list of tasklets to the master queue.
unsigned int GetNumToLoad()
boost::mutex m_masterActiveMutex
std::map< boost::thread::id, unsigned int > m_threadMap
SchedType
Identifies the algorithm for scheduling.
virtual void QueueJob(ThreadJob *job)
Pass a single job to the master queue.
virtual void Hold()
A calling threads holds until all active threads call this method.
virtual void SetNumWorkers()
Sets the number of active workers to the maximum.
boost::thread ** m_threadThreadList
virtual ~ThreadManagerBoost()
Shuts down threading.
ThreadManagerFactory & GetThreadManagerFactory()
unsigned int m_numWorkers
void Stop()
A signal to shut down.
boost::barrier * m_barrier
static ThreadManagerSharedPtr Create(unsigned int numT)
Called by the factory method.
virtual void SetChunkSize(unsigned int chnk)
Controls how many jobs are sent to each worker at a time.
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
Base class for tasks to be sent to the ThreadManager to run.
static std::string className
Implementation class for ThreadManagerBoost.
void SetNumWorkersImpl(const unsigned int num)
virtual unsigned int GetNumWorkers()
Return the number of active workers.
bool * m_threadActiveList
std::queue< ThreadJob * > m_masterQueue
ThreadWorkerBoost ** m_threadList
Implementation of ThreadManager using Boost threads.
boost::condition_variable m_masterActiveCondVar
boost::unique_lock< boost::mutex > Lock
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.