Mantid
Loading...
Searching...
No Matches
Public Member Functions | Protected Types | Protected Attributes | List of all members
Mantid::Kernel::ThreadSchedulerMutexes Class Reference

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>

Inheritance diagram for Mantid::Kernel::ThreadSchedulerMutexes:
Mantid::Kernel::ThreadScheduler

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.
 

Detailed Description

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.

Author
Janik Zikovsky
Date
2011-02-25 16:39:43.233991

Definition at line 37 of file ThreadSchedulerMutexes.h.

Member Typedef Documentation

◆ InnerMap

using Mantid::Kernel::ThreadSchedulerMutexes::InnerMap = std::multimap<double, std::shared_ptr<Task> >
protected

Map to tasks, sorted by cost.

Definition at line 166 of file ThreadSchedulerMutexes.h.

◆ SuperMap

using Mantid::Kernel::ThreadSchedulerMutexes::SuperMap = std::map<std::shared_ptr<std::mutex>, InnerMap>
protected

Map to maps, sorted by Mutex*.

Definition at line 168 of file ThreadSchedulerMutexes.h.

Constructor & Destructor Documentation

◆ ThreadSchedulerMutexes()

Mantid::Kernel::ThreadSchedulerMutexes::ThreadSchedulerMutexes ( )
default

◆ ~ThreadSchedulerMutexes()

Mantid::Kernel::ThreadSchedulerMutexes::~ThreadSchedulerMutexes ( )
inlineoverride

Definition at line 41 of file ThreadSchedulerMutexes.h.

References clear().

Member Function Documentation

◆ clear()

void Mantid::Kernel::ThreadSchedulerMutexes::clear ( )
inlinefinaloverridevirtual

◆ empty()

bool Mantid::Kernel::ThreadSchedulerMutexes::empty ( )
inlineoverridevirtual
Returns
true if the queue is empty

Implements Mantid::Kernel::ThreadScheduler.

Definition at line 140 of file ThreadSchedulerMutexes.h.

References Mantid::Kernel::ThreadScheduler::m_queueLock, and m_supermap.

◆ finished()

void Mantid::Kernel::ThreadSchedulerMutexes::finished ( Task *  task,
size_t  threadnum 
)
inlineoverridevirtual

Signal to the scheduler that a task is complete.

Parameters
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.

◆ pop()

std::shared_ptr< Task > Mantid::Kernel::ThreadSchedulerMutexes::pop ( size_t  threadnum)
inlineoverridevirtual

Retrieves the next Task to execute.

Parameters
threadnum:: ID of the calling thread.
Returns
a Task pointer to execute.

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.

◆ push()

void Mantid::Kernel::ThreadSchedulerMutexes::push ( std::shared_ptr< Task >  newTask)
inlineoverridevirtual

Add a Task to the queue.

Parameters
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.

◆ size()

size_t Mantid::Kernel::ThreadSchedulerMutexes::size ( )
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.

Member Data Documentation

◆ m_mutexes

std::set<std::shared_ptr<std::mutex> > Mantid::Kernel::ThreadSchedulerMutexes::m_mutexes
protected

Vector of currently used mutexes.

Definition at line 175 of file ThreadSchedulerMutexes.h.

Referenced by finished(), and pop().

◆ m_supermap

SuperMap Mantid::Kernel::ThreadSchedulerMutexes::m_supermap
protected

A super map; first key = a Mutex * Inside it: second key = the cost.

Definition at line 172 of file ThreadSchedulerMutexes.h.

Referenced by clear(), empty(), pop(), push(), and size().


The documentation for this class was generated from the following file: