35#ifndef NEKTAR_LIB_UTILITIES_THREAD_H_
36#define NEKTAR_LIB_UTILITIES_THREAD_H_
38#include <boost/thread/condition_variable.hpp>
39#include <boost/thread/locks.hpp>
40#include <boost/thread/mutex.hpp>
41#include <boost/thread/thread.hpp>
362 std::vector<ThreadJob *> &joblist) = 0;
367 const unsigned int num) = 0;
379typedef boost::unique_lock<boost::shared_mutex>
WriteLock;
380typedef boost::shared_lock<boost::shared_mutex>
ReadLock;
446 virtual void v_QueueJobs(std::vector<ThreadJob *> &joblist)
override;
453 virtual void v_Wait()
override;
457 virtual void v_Hold()
override;
459 virtual const std::string &
v_GetType()
const override;
#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 unsigned int v_GetWorkerNum()=0
virtual void v_QueueJobs(std::vector< ThreadJob * > &joblist)=0
unsigned int GetNumWorkers()
Return the number of active workers.
void QueueJobs(std::vector< ThreadJob * > &joblist)
Pass a list of tasklets to the master queue.
bool InThread()
Indicates whether the code is in a worker thread or not.
int GetPartitionFromRankThr(int pRank, unsigned int pThr)
int GetThrFromPartition(int pPartition)
virtual void v_SetSchedType(SchedType s)=0
virtual ~ThreadManager()
Destructor.
void SetNumWorkers(const unsigned int num)
Sets the number of active workers.
void Wait()
Waits until all queued jobs are finished.
virtual bool v_InThread()=0
virtual unsigned int v_GetNumWorkers()=0
void SetSchedType(SchedType s)
Sets the current scheduling algorithm.
void QueueJob(ThreadJob *job)
Pass a single job to the master queue.
virtual void v_QueueJob(ThreadJob *job)=0
virtual void v_SetChunkSize(unsigned int chnk)=0
virtual void v_SetNumWorkers()=0
virtual unsigned int v_GetMaxNumWorkers()=0
const std::string & GetType()
Returns a description of the type of threading.
int GetRankFromPartition(int pPartition)
unsigned int GetMaxNumWorkers()
Gets the maximum available number of threads.
virtual bool v_IsInitialised()
void Hold()
A calling threads holds until all active threads call this method.
unsigned int GetWorkerNum()
Returns the worker number of the executing thread.
bool IsInitialised()
ThreadManager implementation.
void SetNumWorkers()
Sets the number of active workers to the maximum.
virtual const std::string & v_GetType() const =0
void SetChunkSize(unsigned int chnk)
Controls how many jobs are sent to each worker at a time.
virtual void v_SetNumWorkers(const unsigned int num)=0
~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 v_IsInitialised() override
virtual unsigned int v_GetWorkerNum() override
virtual ~ThreadStartupManager()
ThreadStartupManager & operator=(const ThreadStartupManager &src)
ThreadDefaultManager copy constructor.
virtual unsigned int v_GetMaxNumWorkers() override
ThreadStartupManager()
ThreadDefaultManager.
virtual void v_SetSchedType(SchedType s) override
virtual void v_SetNumWorkers() override
virtual void v_QueueJob(ThreadJob *job) override
virtual bool v_InThread() override
ThreadStartupManager(const ThreadStartupManager &src)=default
virtual void v_QueueJobs(std::vector< ThreadJob * > &joblist) override
virtual unsigned int v_GetNumWorkers() override
virtual void v_Hold() override
virtual void v_SetChunkSize(unsigned int chnk) override
virtual void v_Wait() override
virtual const std::string & v_GetType() const override
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.