35 #ifndef NEKTAR_LIB_UTILITIES_THREAD_H_
36 #define NEKTAR_LIB_UTILITIES_THREAD_H_
41 #include <boost/thread/mutex.hpp>
42 #include <boost/thread/locks.hpp>
43 #include <boost/thread/condition_variable.hpp>
44 #include <boost/thread/thread.hpp>
322 typedef boost::unique_lock<boost::shared_mutex>
WriteLock;
323 typedef boost::shared_lock<boost::shared_mutex>
ReadLock;
387 virtual void QueueJobs(std::vector<ThreadJob*>& joblist);
400 virtual const std::string&
GetType()
const;
#define LIB_UTILITIES_EXPORT
Provides a generic Factory class.
Base class for tasks to be sent to the ThreadManager to run.
virtual ~ThreadJob()
Base destructor.
void SetWorkerNum(unsigned int num)
Set number of worker threads.
ThreadJob()
Base constructor.
unsigned int GetWorkerNum()
The interface class for the controller for worker threads and jobs.
virtual void SetNumWorkers(const unsigned int num)=0
Sets the number of active workers.
virtual unsigned int GetWorkerNum()=0
Returns the worker number of the executing thread.
virtual unsigned int GetNumWorkers()=0
Return the number of active workers.
virtual void SetNumWorkers()=0
Sets the number of active workers to the maximum.
virtual void QueueJobs(std::vector< ThreadJob * > &joblist)=0
Pass a list of tasklets to the master queue.
virtual const std::string & GetType() const =0
Returns a description of the type of threading.
int GetPartitionFromRankThr(int pRank, unsigned int pThr)
int GetThrFromPartition(int pPartition)
virtual ~ThreadManager()
Destructor.
virtual unsigned int GetMaxNumWorkers()=0
Gets the maximum available number of threads.
virtual void SetChunkSize(unsigned int chnk)=0
Controls how many jobs are sent to each worker at a time.
virtual bool InThread()=0
Indicates whether the code is in a worker thread or not.
int GetRankFromPartition(int pPartition)
virtual void Hold()=0
A calling threads holds until all active threads call this method.
virtual void QueueJob(ThreadJob *job)=0
Pass a single job to the master queue.
virtual bool IsInitialised()
ThreadManager implementation.
virtual void SetSchedType(SchedType s)=0
Sets the current scheduling algorithm.
virtual void Wait()=0
Waits until all queued jobs are finished.
~ThreadMaster()
Destructor.
void SetThreadingType(const std::string &p_type)
Sets what ThreadManagers will be created in CreateInstance.
ThreadManagerSharedPtr CreateInstance(const ThreadManagerName t, unsigned int nThr)
Creates an instance of a ThreadManager (which one is determined by a previous call to SetThreadingTyp...
ThreadManagerSharedPtr & GetInstance(const ThreadManagerName t)
Gets the ThreadManager associated with string s.
ThreadMaster()
Constructor.
std::vector< ThreadManagerSharedPtr > m_threadManagers
boost::shared_mutex m_mutex
std::string m_threadingType
virtual bool IsInitialised()
ThreadManager implementation.
virtual void SetChunkSize(unsigned int chnk)
Controls how many jobs are sent to each worker at a time.
virtual void Wait()
Waits until all queued jobs are finished.
virtual ~ThreadStartupManager()
ThreadStartupManager & operator=(const ThreadStartupManager &src)
ThreadDefaultManager copy constructor.
virtual unsigned int GetNumWorkers()
Return the number of active workers.
virtual unsigned int GetMaxNumWorkers()
Gets the maximum available number of threads.
ThreadStartupManager()
ThreadDefaultManager.
virtual void SetNumWorkers()
Sets the number of active workers to the maximum.
virtual bool InThread()
Indicates whether the code is in a worker thread or not.
ThreadStartupManager(const ThreadStartupManager &src)=default
virtual const std::string & GetType() const
Returns a description of the type of threading.
virtual void QueueJobs(std::vector< ThreadJob * > &joblist)
Pass a list of tasklets to the master queue.
virtual void SetSchedType(SchedType s)
Sets the current scheduling algorithm.
virtual void QueueJob(ThreadJob *job)
Pass a single job to the master queue.
virtual unsigned int GetWorkerNum()
Returns the worker number of the executing thread.
virtual void Hold()
A calling threads holds until all active threads call this method.
SchedType
Identifies the algorithm for scheduling.
LibUtilities::NekFactory< std::string, ThreadManager, unsigned int > ThreadManagerFactory
ThreadManagerFactory & GetThreadManagerFactory()
std::shared_ptr< ThreadManager > ThreadManagerSharedPtr
boost::shared_lock< boost::shared_mutex > ReadLock
ThreadMaster & GetThreadMaster()
boost::unique_lock< boost::shared_mutex > WriteLock
The above copyright notice and this permission notice shall be included.