|
Mantid
|
ThreadSchedulerMutexes : Version of a ThreadSchedulerLargestCost that also makes sure to not try to schedule two tasks with the same mutex at the same time. More...
#include <ThreadSchedulerMutexes.h>
Public Member Functions | |
| void | clear () override final |
| Empty out the queue. | |
| bool | empty () override |
| void | finished (Task *task, size_t threadnum) override |
| Signal to the scheduler that a task is complete. | |
| std::shared_ptr< Task > | pop (size_t threadnum) override |
| Retrieves the next Task to execute. | |
| void | push (std::shared_ptr< Task > newTask) override |
| Add a Task to the queue. | |
| size_t | size () override |
| Returns the size of the queue. | |
| ThreadSchedulerMutexes ()=default | |
| ~ThreadSchedulerMutexes () override | |
Public Member Functions inherited from Mantid::Kernel::ThreadScheduler | |
| virtual void | abort (std::runtime_error exception) |
| Signal to the scheduler that a task is complete. | |
| bool | getAborted () |
| Returns true if the execution was aborted. | |
| std::runtime_error | getAbortException () |
| Returns the exception that was caught, if any. | |
| bool | hasBusyThreads () const |
| Returns true if any thread is busy. | |
| void | markBusy () |
| Mark a thread as busy. | |
| void | markIdle () |
| Mark a thread as no longer busy. See markBusy(). | |
| ThreadScheduler () | |
| Constructor. | |
| double | totalCost () |
| Returns the total cost of all Task's in the queue. | |
| double | totalCostExecuted () |
| Returns the total cost of all Task's in the queue. | |
| virtual | ~ThreadScheduler ()=default |
| Destructor. | |
Protected Types | |
| using | InnerMap = std::multimap< double, std::shared_ptr< Task > > |
| Map to tasks, sorted by cost. | |
| using | SuperMap = std::map< std::shared_ptr< std::mutex >, InnerMap > |
| Map to maps, sorted by Mutex*. | |
Protected Attributes | |
| std::set< std::shared_ptr< std::mutex > > | m_mutexes |
| Vector of currently used mutexes. | |
| SuperMap | m_supermap |
| A super map; first key = a Mutex * Inside it: second key = the cost. | |
Protected Attributes inherited from Mantid::Kernel::ThreadScheduler | |
| bool | m_aborted |
| The run was aborted due to an exception. | |
| std::runtime_error | m_abortException |
| The exception that aborted the run. | |
| double | m_cost |
| Total cost of all tasks. | |
| double | m_costExecuted |
| Accumulated cost of tasks that have been executed (popped) | |
| std::atomic< size_t > | m_numBusyThreads {0} |
| Number of threads that are getting or running a task. | |
| std::mutex | m_queueLock |
| Mutex to prevent simultaneous access to the queue. | |
ThreadSchedulerMutexes : Version of a ThreadSchedulerLargestCost that also makes sure to not try to schedule two tasks with the same mutex at the same time.
This scheduler also sorts by largest cost so as to optimize allocation that way.
NOTE: The performance of "pop"ping a task is much slower if you have a very large number of different mutexes; this scheduler is better suited if you only have a few (e.g. one for DiskIO, and NULL for calculations). Popping a task scales with the N^2 where N is the number of different mutexes.
Definition at line 37 of file ThreadSchedulerMutexes.h.
|
protected |
Map to tasks, sorted by cost.
Definition at line 166 of file ThreadSchedulerMutexes.h.
|
protected |
Map to maps, sorted by Mutex*.
Definition at line 168 of file ThreadSchedulerMutexes.h.
|
default |
|
inlineoverride |
Definition at line 41 of file ThreadSchedulerMutexes.h.
References clear().
|
inlinefinaloverridevirtual |
Empty out the queue.
Implements Mantid::Kernel::ThreadScheduler.
Definition at line 151 of file ThreadSchedulerMutexes.h.
References Mantid::Kernel::ThreadScheduler::m_cost, Mantid::Kernel::ThreadScheduler::m_costExecuted, Mantid::Kernel::ThreadScheduler::m_queueLock, and m_supermap.
Referenced by ~ThreadSchedulerMutexes().
|
inlineoverridevirtual |
Implements Mantid::Kernel::ThreadScheduler.
Definition at line 140 of file ThreadSchedulerMutexes.h.
References Mantid::Kernel::ThreadScheduler::m_queueLock, and m_supermap.
|
inlineoverridevirtual |
Signal to the scheduler that a task is complete.
| task | :: the Task that was completed. |
| threadnum | :: unused argument |
Reimplemented from Mantid::Kernel::ThreadScheduler.
Definition at line 117 of file ThreadSchedulerMutexes.h.
References Mantid::Kernel::Task::getMutex(), m_mutexes, Mantid::Kernel::ThreadScheduler::m_queueLock, and UNUSED_ARG.
|
inlineoverridevirtual |
Retrieves the next Task to execute.
| threadnum | :: ID of the calling thread. |
Implements Mantid::Kernel::ThreadScheduler.
Definition at line 54 of file ThreadSchedulerMutexes.h.
References m_mutexes, Mantid::Kernel::ThreadScheduler::m_queueLock, m_supermap, and UNUSED_ARG.
|
inlineoverridevirtual |
Add a Task to the queue.
| newTask | :: Task to add to queue |
Implements Mantid::Kernel::ThreadScheduler.
Definition at line 44 of file ThreadSchedulerMutexes.h.
References Mantid::Kernel::ThreadScheduler::m_cost, Mantid::Kernel::ThreadScheduler::m_queueLock, and m_supermap.
|
inlineoverridevirtual |
Returns the size of the queue.
Implements Mantid::Kernel::ThreadScheduler.
Definition at line 128 of file ThreadSchedulerMutexes.h.
References Mantid::Kernel::ThreadScheduler::m_queueLock, and m_supermap.
|
protected |
Vector of currently used mutexes.
Definition at line 175 of file ThreadSchedulerMutexes.h.
Referenced by finished(), and pop().
|
protected |