Nektar++
|
Implementation of ThreadManager using std::thread. More...
#include <ThreadStd.h>
Classes | |
class | Barrier |
Lightweight barrier class. More... | |
Public Member Functions | |
ThreadManagerStd (unsigned int numWorkers) | |
Constructs a ThreadManagerStd. More... | |
~ThreadManagerStd () override | |
Shuts down threading. More... | |
Public Member Functions inherited from Nektar::Thread::ThreadManager | |
virtual | ~ThreadManager () |
Destructor. More... | |
void | QueueJobs (std::vector< ThreadJob * > &joblist) |
Pass a list of tasklets to the master queue. More... | |
void | QueueJob (ThreadJob *job) |
Pass a single job to the master queue. More... | |
unsigned int | GetNumWorkers () |
Return the number of active workers. More... | |
unsigned int | GetWorkerNum () |
Returns the worker number of the executing thread. More... | |
void | SetNumWorkers (const unsigned int num) |
Sets the number of active workers. More... | |
void | SetNumWorkers () |
Sets the number of active workers to the maximum. More... | |
unsigned int | GetMaxNumWorkers () |
Gets the maximum available number of threads. More... | |
void | Wait () |
Waits until all queued jobs are finished. More... | |
void | SetChunkSize (unsigned int chnk) |
Controls how many jobs are sent to each worker at a time. More... | |
void | SetSchedType (SchedType s) |
Sets the current scheduling algorithm. More... | |
bool | InThread () |
Indicates whether the code is in a worker thread or not. More... | |
void | Hold () |
A calling threads holds until all active threads call this method. More... | |
const std::string & | GetType () |
Returns a description of the type of threading. More... | |
bool | IsInitialised () |
ThreadManager implementation. More... | |
int | GetThrFromPartition (int pPartition) |
int | GetRankFromPartition (int pPartition) |
int | GetPartitionFromRankThr (int pRank, unsigned int pThr) |
Static Public Member Functions | |
static ThreadManagerSharedPtr | Create (unsigned int numT) |
Called by the factory method. More... | |
Protected Member Functions | |
void | v_QueueJobs (std::vector< ThreadJob * > &joblist) override |
void | v_QueueJob (ThreadJob *job) override |
unsigned int | v_GetNumWorkers () override |
unsigned int | v_GetWorkerNum () override |
void | v_SetNumWorkers (const unsigned int num) override |
void | v_SetNumWorkers () override |
unsigned int | v_GetMaxNumWorkers () override |
void | v_Wait () override |
void | v_SetChunkSize (unsigned int chnk) override |
void | v_SetSchedType (SchedType s) override |
bool | v_InThread () override |
void | v_Hold () override |
const std::string & | v_GetType () const override |
Protected Member Functions inherited from Nektar::Thread::ThreadManager | |
virtual void | v_QueueJobs (std::vector< ThreadJob * > &joblist)=0 |
virtual void | v_QueueJob (ThreadJob *job)=0 |
virtual unsigned int | v_GetNumWorkers ()=0 |
virtual unsigned int | v_GetWorkerNum ()=0 |
virtual void | v_SetNumWorkers (const unsigned int num)=0 |
virtual void | v_SetNumWorkers ()=0 |
virtual unsigned int | v_GetMaxNumWorkers ()=0 |
virtual void | v_Wait ()=0 |
virtual void | v_SetChunkSize (unsigned int chnk)=0 |
virtual void | v_SetSchedType (SchedType s)=0 |
virtual bool | v_InThread ()=0 |
virtual void | v_Hold ()=0 |
virtual const std::string & | v_GetType () const =0 |
virtual bool | v_IsInitialised () |
Private Member Functions | |
ThreadManagerStd () | |
ThreadManagerStd (const ThreadManagerStd &) | |
bool | IsWorking () |
void | SetNumWorkersImpl (const unsigned int num) |
Private Attributes | |
const unsigned int | m_numThreads |
unsigned int | m_numWorkers |
std::queue< ThreadJob * > | m_masterQueue |
std::mutex | m_masterQueueMutex |
std::mutex | m_masterActiveMutex |
std::condition_variable | m_masterQueueCondVar |
std::condition_variable | m_masterActiveCondVar |
ThreadWorkerStd ** | m_threadList |
std::thread ** | m_threadThreadList |
std::thread::id | m_masterThreadId |
bool * | m_threadBusyList |
bool * | m_threadActiveList |
unsigned int | m_chunkSize |
SchedType | m_schedType |
Barrier * | m_barrier |
std::map< std::thread::id, unsigned int > | m_threadMap |
std::string | m_type |
Static Private Attributes | |
static std::string | className |
Friends | |
class | ThreadWorkerStd |
Implementation of ThreadManager using std::thread.
Definition at line 57 of file ThreadStd.h.
Nektar::Thread::ThreadManagerStd::ThreadManagerStd | ( | unsigned int | numT | ) |
Constructs a ThreadManagerStd.
numWorkers | The number of threads to start (including master thread). |
Definition at line 54 of file ThreadStd.cpp.
References m_barrier, m_masterThreadId, m_numThreads, m_numWorkers, m_threadActiveList, m_threadBusyList, m_threadList, m_threadMap, m_threadThreadList, m_type, and ThreadWorkerStd.
|
override |
Shuts down threading.
Terminates all running threads (they will finish their current job), releases resources and destructs.
Definition at line 115 of file ThreadStd.cpp.
References m_barrier, m_masterActiveCondVar, m_masterQueueCondVar, m_numThreads, m_threadActiveList, m_threadBusyList, m_threadList, m_threadThreadList, and Nektar::Thread::ThreadWorkerStd::Stop().
|
private |
Referenced by Create().
|
private |
|
inlinestatic |
Called by the factory method.
Definition at line 104 of file ThreadStd.h.
References ThreadManagerStd().
|
private |
Definition at line 165 of file ThreadStd.cpp.
References m_masterActiveMutex, m_numWorkers, and m_threadBusyList.
Referenced by v_Wait().
|
private |
Definition at line 242 of file ThreadStd.cpp.
References m_barrier, m_masterActiveCondVar, m_masterActiveMutex, m_numThreads, m_numWorkers, and m_threadActiveList.
Referenced by v_SetNumWorkers().
|
overrideprotectedvirtual |
Implements Nektar::Thread::ThreadManager.
Definition at line 284 of file ThreadStd.cpp.
References m_numThreads.
|
overrideprotectedvirtual |
Implements Nektar::Thread::ThreadManager.
Definition at line 225 of file ThreadStd.cpp.
References m_numWorkers.
|
overrideprotectedvirtual |
Implements Nektar::Thread::ThreadManager.
Definition at line 300 of file ThreadStd.cpp.
References m_type.
|
overrideprotectedvirtual |
Implements Nektar::Thread::ThreadManager.
Definition at line 233 of file ThreadStd.cpp.
References m_threadMap.
|
overrideprotectedvirtual |
Implements Nektar::Thread::ThreadManager.
Definition at line 292 of file ThreadStd.cpp.
References m_barrier, and Nektar::Thread::ThreadManagerStd::Barrier::Wait().
|
overrideprotectedvirtual |
Implements Nektar::Thread::ThreadManager.
Definition at line 197 of file ThreadStd.cpp.
References m_masterThreadId.
Implements Nektar::Thread::ThreadManager.
Definition at line 155 of file ThreadStd.cpp.
References m_masterQueue, m_masterQueueCondVar, and m_masterQueueMutex.
|
overrideprotectedvirtual |
Implements Nektar::Thread::ThreadManager.
Definition at line 143 of file ThreadStd.cpp.
References Nektar::Thread::ThreadManager::QueueJob().
|
overrideprotectedvirtual |
Implements Nektar::Thread::ThreadManager.
Definition at line 179 of file ThreadStd.cpp.
References m_chunkSize, and m_masterQueueMutex.
|
overrideprotectedvirtual |
Implements Nektar::Thread::ThreadManager.
Definition at line 276 of file ThreadStd.cpp.
References m_numThreads, and SetNumWorkersImpl().
|
overrideprotectedvirtual |
Implements Nektar::Thread::ThreadManager.
Definition at line 265 of file ThreadStd.cpp.
References m_numThreads, and SetNumWorkersImpl().
Implements Nektar::Thread::ThreadManager.
Definition at line 188 of file ThreadStd.cpp.
References m_masterQueueMutex, and m_schedType.
|
overrideprotectedvirtual |
Implements Nektar::Thread::ThreadManager.
Definition at line 206 of file ThreadStd.cpp.
References IsWorking(), m_masterActiveCondVar, m_masterQueue, m_masterQueueCondVar, and m_masterQueueMutex.
|
friend |
So the workers can access the master queue and locks.
Definition at line 95 of file ThreadStd.h.
Referenced by ThreadManagerStd().
|
staticprivate |
Definition at line 147 of file ThreadStd.h.
|
private |
Definition at line 145 of file ThreadStd.h.
Referenced by SetNumWorkersImpl(), ThreadManagerStd(), v_Hold(), and ~ThreadManagerStd().
|
private |
Definition at line 143 of file ThreadStd.h.
Referenced by Nektar::Thread::ThreadWorkerStd::GetNumToLoad(), and v_SetChunkSize().
|
private |
Definition at line 137 of file ThreadStd.h.
Referenced by SetNumWorkersImpl(), v_Wait(), Nektar::Thread::ThreadWorkerStd::WaitForActive(), and ~ThreadManagerStd().
|
private |
Definition at line 135 of file ThreadStd.h.
Referenced by IsWorking(), Nektar::Thread::ThreadWorkerStd::LoadJobs(), SetNumWorkersImpl(), and Nektar::Thread::ThreadWorkerStd::WaitForActive().
|
private |
Definition at line 133 of file ThreadStd.h.
Referenced by Nektar::Thread::ThreadWorkerStd::GetNumToLoad(), Nektar::Thread::ThreadWorkerStd::LoadJobs(), v_QueueJob(), and v_Wait().
|
private |
Definition at line 136 of file ThreadStd.h.
Referenced by Nektar::Thread::ThreadWorkerStd::LoadJobs(), v_QueueJob(), v_Wait(), and ~ThreadManagerStd().
|
private |
Definition at line 134 of file ThreadStd.h.
Referenced by Nektar::Thread::ThreadWorkerStd::LoadJobs(), v_QueueJob(), v_SetChunkSize(), v_SetSchedType(), and v_Wait().
|
private |
Definition at line 140 of file ThreadStd.h.
Referenced by ThreadManagerStd(), and v_InThread().
|
private |
Definition at line 131 of file ThreadStd.h.
Referenced by SetNumWorkersImpl(), ThreadManagerStd(), v_GetMaxNumWorkers(), v_SetNumWorkers(), and ~ThreadManagerStd().
|
private |
Definition at line 132 of file ThreadStd.h.
Referenced by Nektar::Thread::ThreadWorkerStd::GetNumToLoad(), IsWorking(), SetNumWorkersImpl(), ThreadManagerStd(), and v_GetNumWorkers().
|
private |
Definition at line 144 of file ThreadStd.h.
Referenced by Nektar::Thread::ThreadWorkerStd::GetNumToLoad(), and v_SetSchedType().
|
private |
Definition at line 142 of file ThreadStd.h.
Referenced by Nektar::Thread::ThreadWorkerStd::LoadJobs(), SetNumWorkersImpl(), ThreadManagerStd(), Nektar::Thread::ThreadWorkerStd::WaitForActive(), and ~ThreadManagerStd().
|
private |
Definition at line 141 of file ThreadStd.h.
Referenced by IsWorking(), Nektar::Thread::ThreadWorkerStd::LoadJobs(), ThreadManagerStd(), and ~ThreadManagerStd().
|
private |
Definition at line 138 of file ThreadStd.h.
Referenced by ThreadManagerStd(), and ~ThreadManagerStd().
|
private |
Definition at line 146 of file ThreadStd.h.
Referenced by ThreadManagerStd(), and v_GetWorkerNum().
|
private |
Definition at line 139 of file ThreadStd.h.
Referenced by ThreadManagerStd(), and ~ThreadManagerStd().
|
private |
Definition at line 148 of file ThreadStd.h.
Referenced by ThreadManagerStd(), and v_GetType().