NeoPZ
|
Administers tasks that will be executed asynchronously. More...
#include <TPZThreadPool.h>
Public Member Functions | |
std::shared_future< void > | run (const int priority, TPZAutoPointer< std::packaged_task< void(void) > > &task, TPZTaskGroup *taskGroup=NULL) |
submits a task to be executed by TPZThreadPool More... | |
void | run (TPZAutoPointer< TPZReschedulableTask > &task) |
void | reschedule (const int priority, TPZAutoPointer< TPZReschedulableTask > &task) |
std::shared_future< void > | runNow (TPZAutoPointer< TPZReschedulableTask > &task) |
template<typename... Args> | |
std::shared_future< void > | run (const int priority, TPZTaskGroup *taskGroup, std::function< void(Args...) > func, Args... args) |
template<typename... Args> | |
TPZAutoPointer< TPZReschedulableTask > | runReschedulable (const int priority, TPZTaskGroup *taskGroup, std::function< void(Args...) > func, Args... args) |
void | SetNumThreads (const unsigned numThreads) |
sets the number of threads to be executed simultaneously More... | |
int | maxPriority () const |
int | minPriority () const |
int | threadCount () const |
Static Public Member Functions | |
static TPZThreadPool & | globalInstance () |
Private Member Functions | |
TPZThreadPool () | |
int | ActualThreadCount () const |
void | threadsLoop () |
void | updatePriorities () |
void | appendTaskToQueue (TPZAutoPointer< TPZTask > &task) |
TPZAutoPointer< TPZTask > | appendTaskToQueue (const int priority, TPZAutoPointer< std::packaged_task< void(void) >> &task, const bool system_task, TPZTaskGroup *taskGroup=NULL) |
void | checkForMaxAndMinPriority (const int priority) |
~TPZThreadPool () | |
template<typename... Args> | |
std::shared_future< void > | runSystemTask (const int priority, std::function< void(Args...) > func, Args... args) |
Submits and processes a "maximum priority" system task. More... | |
Private Attributes | |
std::vector< std::thread > | mThreads |
vector of thread objects More... | |
std::mutex | mThreadsMutex |
one mutex to synchronize access to the data structures More... | |
unsigned int | mThreadsToDelete |
unsigned int | mZombieThreads |
bool | mStop |
TPZPriorityQueue< TPZAutoPointer< TPZTask >, std::vector< TPZAutoPointer< TPZTask > >, TPZTaskOrdering > | mTasksQueue |
std::condition_variable | mTaskAvailableCond |
int | mMinPriority |
int | mMaxPriority |
Administers tasks that will be executed asynchronously.
Definition at line 23 of file TPZThreadPool.h.
|
private |
Definition at line 105 of file TPZThreadPool.cpp.
References appendTaskToQueue(), TPZTask::priority(), run(), and threadCount().
Referenced by runReschedulable().
|
private |
Definition at line 131 of file TPZThreadPool.cpp.
References TPZPriorityQueue< T, Container, Compare >::mMutex, mStop, mTaskAvailableCond, mTasksQueue, mThreads, and mThreadsMutex.
Referenced by runReschedulable().
|
private |
Definition at line 159 of file TPZThreadPool.cpp.
References mThreads.
Referenced by runReschedulable(), threadCount(), and threadsLoop().
|
private |
Definition at line 163 of file TPZThreadPool.cpp.
References TPZPriorityQueue< T, Container, Compare >::addItem(), TPZPriorityQueue< T, Container, Compare >::mMutex, TPZTask::mSystemTask, mTaskAvailableCond, mTasksQueue, and TPZTask::TPZTask().
Referenced by reschedule(), run(), runNow(), runReschedulable(), runSystemTask(), and TPZThreadPool().
|
private |
|
private |
Definition at line 176 of file TPZThreadPool.cpp.
References mMaxPriority, mMinPriority, and TPZTask::priority().
Referenced by run(), runReschedulable(), and runSystemTask().
|
static |
Definition at line 238 of file TPZThreadPool.cpp.
Referenced by TPZRenumbering::ColorElements(), TPZStructMatrixGCTP::MultiThread_Assemble(), runNow(), and TPZStructMatrixBase::TPZStructMatrixBase().
int TPZThreadPool::maxPriority | ( | ) | const |
Definition at line 147 of file TPZThreadPool.cpp.
References mMaxPriority.
Referenced by runReschedulable().
int TPZThreadPool::minPriority | ( | ) | const |
Definition at line 151 of file TPZThreadPool.cpp.
References mMinPriority.
Referenced by runReschedulable().
void TPZThreadPool::reschedule | ( | const int | priority, |
TPZAutoPointer< TPZReschedulableTask > & | task | ||
) |
Definition at line 121 of file TPZThreadPool.cpp.
References appendTaskToQueue(), TPZPriorityQueue< T, Container, Compare >::mMutex, mTasksQueue, TPZTask::priority(), and TPZPriorityQueue< T, Container, Compare >::remove().
Referenced by runNow().
std::shared_future<void> TPZThreadPool::run | ( | const int | priority, |
TPZAutoPointer< std::packaged_task< void(void) > > & | task, | ||
TPZTaskGroup * | taskGroup = NULL |
||
) |
submits a task to be executed by TPZThreadPool
Referenced by TPZRenumbering::ColorElements(), TPZStructMatrixGCTP::MultiThread_Assemble(), run(), runReschedulable(), and TPZThreadPool().
void TPZThreadPool::run | ( | TPZAutoPointer< TPZReschedulableTask > & | task | ) |
Definition at line 214 of file TPZThreadPool.cpp.
References appendTaskToQueue(), TPZReschedulableTask::mCondition, TPZReschedulableTask::mFuture, TPZTask::mState, TPZReschedulableTask::mStateMutex, TPZTask::mTask, TPZReschedulableTask::startInternal(), and threadCount().
|
inline |
Definition at line 38 of file TPZThreadPool.h.
References checkForMaxAndMinPriority(), and run().
std::shared_future< void > TPZThreadPool::runNow | ( | TPZAutoPointer< TPZReschedulableTask > & | task | ) |
Definition at line 185 of file TPZThreadPool.cpp.
References appendTaskToQueue(), TPZTask::FINISHED, globalInstance(), TPZReschedulableTask::mCondition, TPZReschedulableTask::mFuture, TPZTask::mPriority, TPZTask::mState, TPZReschedulableTask::mStateMutex, TPZTask::mTask, reschedule(), TPZTask::SCHEDULED, TPZTask::STARTED, TPZReschedulableTask::startInternal(), and threadCount().
|
inline |
Definition at line 45 of file TPZThreadPool.h.
References ActualThreadCount(), appendTaskToQueue(), checkForMaxAndMinPriority(), maxPriority(), minPriority(), run(), SetNumThreads(), threadCount(), threadsLoop(), TPZThreadPool(), updatePriorities(), and ~TPZThreadPool().
|
inlineprivate |
Submits and processes a "maximum priority" system task.
Definition at line 74 of file TPZThreadPool.h.
References appendTaskToQueue(), and checkForMaxAndMinPriority().
Referenced by threadsLoop().
void TPZThreadPool::SetNumThreads | ( | const unsigned | numThreads | ) |
sets the number of threads to be executed simultaneously
Definition at line 87 of file TPZThreadPool.cpp.
References mTaskAvailableCond, mThreads, mThreadsMutex, mThreadsToDelete, threadCount(), and threadsLoop().
Referenced by runReschedulable().
int TPZThreadPool::threadCount | ( | ) | const |
Definition at line 155 of file TPZThreadPool.cpp.
References ActualThreadCount(), mThreadsToDelete, and mZombieThreads.
Referenced by TPZRenumbering::ColorElements(), run(), runNow(), runReschedulable(), SetNumThreads(), and TPZThreadPool().
|
private |
Definition at line 27 of file TPZThreadPool.cpp.
References ActualThreadCount(), TPZTask::Cancel(), TPZPriorityQueue< T, Container, Compare >::mMutex, mStop, mTaskAvailableCond, mTasksQueue, mThreads, mThreadsMutex, mThreadsToDelete, mZombieThreads, num_threads, TPZPriorityQueue< T, Container, Compare >::popTop(), runSystemTask(), TPZPriorityQueue< T, Container, Compare >::size(), TPZTask::start(), TPZPriorityQueue< T, Container, Compare >::top(), and updatePriorities().
Referenced by runReschedulable(), and SetNumThreads().
|
private |
Definition at line 18 of file TPZThreadPool.cpp.
References mMaxPriority, mMinPriority, mTasksQueue, TPZPriorityQueue< T, Container, Compare >::size(), and TPZPriorityQueue< T, Container, Compare >::top().
Referenced by runReschedulable(), and threadsLoop().
|
private |
Definition at line 92 of file TPZThreadPool.h.
Referenced by checkForMaxAndMinPriority(), maxPriority(), and updatePriorities().
|
private |
Definition at line 91 of file TPZThreadPool.h.
Referenced by checkForMaxAndMinPriority(), minPriority(), and updatePriorities().
|
private |
Definition at line 88 of file TPZThreadPool.h.
Referenced by threadsLoop(), and ~TPZThreadPool().
|
private |
Definition at line 90 of file TPZThreadPool.h.
Referenced by appendTaskToQueue(), SetNumThreads(), threadsLoop(), and ~TPZThreadPool().
|
private |
Definition at line 89 of file TPZThreadPool.h.
Referenced by appendTaskToQueue(), reschedule(), threadsLoop(), updatePriorities(), and ~TPZThreadPool().
|
private |
vector of thread objects
Definition at line 83 of file TPZThreadPool.h.
Referenced by ActualThreadCount(), SetNumThreads(), threadsLoop(), and ~TPZThreadPool().
|
private |
one mutex to synchronize access to the data structures
Definition at line 85 of file TPZThreadPool.h.
Referenced by SetNumThreads(), threadsLoop(), and ~TPZThreadPool().
|
private |
Definition at line 86 of file TPZThreadPool.h.
Referenced by SetNumThreads(), threadCount(), and threadsLoop().
|
private |
Definition at line 87 of file TPZThreadPool.h.
Referenced by threadCount(), and threadsLoop().