Nektar++
|
A default ThreadManager. More...
#include <Thread.h>
Public Member Functions | |
ThreadStartupManager () | |
ThreadDefaultManager. More... | |
virtual | ~ThreadStartupManager () |
virtual void | QueueJobs (std::vector< ThreadJob * > &joblist) |
Pass a list of tasklets to the master queue. More... | |
virtual void | QueueJob (ThreadJob *job) |
Pass a single job to the master queue. More... | |
virtual unsigned int | GetNumWorkers () |
Return the number of active workers. More... | |
virtual unsigned int | GetWorkerNum () |
Returns the worker number of the executing thread. More... | |
virtual void | SetNumWorkers (const unsigned int num) |
Sets the number of active workers. More... | |
virtual void | SetNumWorkers () |
Sets the number of active workers to the maximum. More... | |
virtual unsigned int | GetMaxNumWorkers () |
Gets the maximum available number of threads. More... | |
virtual void | Wait () |
Waits until all queued jobs are finished. More... | |
virtual void | SetChunkSize (unsigned int chnk) |
Controls how many jobs are sent to each worker at a time. More... | |
virtual void | SetSchedType (SchedType s) |
Sets the current scheduling algorithm. More... | |
virtual bool | InThread () |
Indicates whether the code is in a worker thread or not. More... | |
virtual void | Hold () |
A calling threads holds until all active threads call this method. More... | |
virtual bool | IsInitialised () |
ThreadManager implementation. More... | |
virtual const std::string & | GetType () const |
Returns a description of the type of threading. More... | |
Public Member Functions inherited from Nektar::Thread::ThreadManager | |
virtual | ~ThreadManager () |
Destructor. More... | |
int | GetThrFromPartition (int pPartition) |
int | GetRankFromPartition (int pPartition) |
int | GetPartitionFromRankThr (int pRank, unsigned int pThr) |
Private Attributes | |
const std::string | m_type |
A default ThreadManager.
This will be returned by ThreadMaster if a ThreadManager has not been initialised, such as if the code is still in static initialisation.
This manager pretends to be a ThreadManager with 1 thread. It will cause an error if anything more than trivial functions are called.
Nektar::Thread::ThreadStartupManager::ThreadStartupManager | ( | ) |
|
virtual |
Definition at line 222 of file Thread.cpp.
|
virtual |
Gets the maximum available number of threads.
Implements Nektar::Thread::ThreadManager.
Definition at line 288 of file Thread.cpp.
|
virtual |
Return the number of active workers.
Active workers are threads that are either running jobs or are waiting for jobs to be queued.
Implements Nektar::Thread::ThreadManager.
Definition at line 251 of file Thread.cpp.
|
virtual |
Returns a description of the type of threading.
E.g. "Threading with Boost"
Implements Nektar::Thread::ThreadManager.
Definition at line 353 of file Thread.cpp.
References m_type.
|
virtual |
Returns the worker number of the executing thread.
Returns an unsigned int between 0 and N-1 where N is the number of active worker threads. Repeated calls from within this thread will always return the same value and the value will be the same as returned from ThreadJob.GetWorkerNum(). The same thread will run a job until it finishes.
Although if there are active threads then thread 0 is always one of them, it is possible that thread 0 does not run for a given set of jobs. For example, if there are 4 active threads and 3 jobs are submitted with a e_static scheduling strategy and a chunksize of 1, then it is possible that threads 1,2, and 3 pick up the jobs and thread 0 remains idle.
Returns 0 if called by non-thread.
Implements Nektar::Thread::ThreadManager.
Definition at line 260 of file Thread.cpp.
|
virtual |
A calling threads holds until all active threads call this method.
When called, the calling thread will sleep until all active workers have called this method. Once all have done so all threads awake and continue execution.
Implements Nektar::Thread::ThreadManager.
Definition at line 335 of file Thread.cpp.
|
virtual |
Indicates whether the code is in a worker thread or not.
Implements Nektar::Thread::ThreadManager.
Definition at line 326 of file Thread.cpp.
|
virtual |
ThreadManager implementation.
Implementations should not override this function, since they are initialised.
Reimplemented from Nektar::Thread::ThreadManager.
Definition at line 344 of file Thread.cpp.
Pass a single job to the master queue.
job | A pointer to a ThreadJob subclass. |
The job may become available for running immediately. If this is an issue then suspend the workers with SetNumWorkers(0) until the jobs are queued.
Implements Nektar::Thread::ThreadManager.
Definition at line 241 of file Thread.cpp.
References ErrorUtil::efatal, and NEKERROR.
|
virtual |
Pass a list of tasklets to the master queue.
joblist | Vector of ThreadJob pointers. |
The list of jobs is copied into the master queue. Jobs may be available for running immediately, even before the list has been fully copied. This can have consequences for the scheduling. If this is an issue then suspend the workers with SetNumWorkers(0) until the jobs are queued.
Implements Nektar::Thread::ThreadManager.
Definition at line 231 of file Thread.cpp.
References ErrorUtil::efatal, and NEKERROR.
|
virtual |
Controls how many jobs are sent to each worker at a time.
The exact meaning of this parameter depends on the current scheduling algorithm.
Implements Nektar::Thread::ThreadManager.
Definition at line 306 of file Thread.cpp.
References ErrorUtil::efatal, and NEKERROR.
|
virtual |
Sets the number of active workers.
num | The number of active workers. |
Active workers are threads that are either running jobs or are waiting for jobs to be queued.
If num is greater than the maximum allowed number of active workers, then the maximum value will be used instead.
Implements Nektar::Thread::ThreadManager.
Definition at line 269 of file Thread.cpp.
References ASSERTL0.
|
virtual |
Sets the number of active workers to the maximum.
Sets the number of active workers to the maximum available.
Implements Nektar::Thread::ThreadManager.
Definition at line 279 of file Thread.cpp.
Sets the current scheduling algorithm.
Implements Nektar::Thread::ThreadManager.
Definition at line 316 of file Thread.cpp.
References ErrorUtil::efatal, and NEKERROR.
|
virtual |
Waits until all queued jobs are finished.
If there are no jobs running or queued this method returns immediately. Otherwise it blocks until the queue is empty and the worker threads are idle.
Implementations must ensure that trivial deadlocks are not possible from this method, that is, that this code:
does not wait forever. Since the master thread is counted in the number of worker threads, implementations should increase the number of active workers by 1 on entering Wait().
Implements Nektar::Thread::ThreadManager.
Definition at line 297 of file Thread.cpp.