35#ifndef NEKTAR_LIB_UTILITIES_THREAD_H_
36#define NEKTAR_LIB_UTILITIES_THREAD_H_
41#include <shared_mutex>
359 std::vector<ThreadJob *> &joblist) = 0;
364 const unsigned int num) = 0;
377typedef std::shared_lock<std::shared_mutex>
ReadLock;
443 void v_QueueJobs(std::vector<ThreadJob *> &joblist)
override;
456 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.
std::shared_mutex m_mutex
ThreadMaster()
Constructor.
std::vector< ThreadManagerSharedPtr > m_threadManagers
std::string m_threadingType
bool v_IsInitialised() override
unsigned int v_GetWorkerNum() override
ThreadStartupManager & operator=(const ThreadStartupManager &src)
ThreadDefaultManager copy constructor.
unsigned int v_GetMaxNumWorkers() override
ThreadStartupManager()
ThreadDefaultManager.
void v_SetSchedType(SchedType s) override
void v_SetNumWorkers() override
void v_QueueJob(ThreadJob *job) override
bool v_InThread() override
ThreadStartupManager(const ThreadStartupManager &src)=default
void v_QueueJobs(std::vector< ThreadJob * > &joblist) override
unsigned int v_GetNumWorkers() override
void v_SetChunkSize(unsigned int chnk) override
const std::string & v_GetType() const override
~ThreadStartupManager() override
SchedType
Identifies the algorithm for scheduling.
std::shared_lock< std::shared_mutex > ReadLock
std::unique_lock< std::shared_mutex > WriteLock
LibUtilities::NekFactory< std::string, ThreadManager, unsigned int > ThreadManagerFactory
ThreadManagerFactory & GetThreadManagerFactory()
std::shared_ptr< ThreadManager > ThreadManagerSharedPtr
ThreadMaster & GetThreadMaster()