ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itk::PlatformMultiThreader Class Reference

#include <itkPlatformMultiThreader.h>

Detailed Description

A class for performing multithreaded execution.

Multithreader is a class that provides support for multithreaded execution using Windows or POSIX threads. This class can be used to execute a single method on multiple threads, or to specify a method per thread.

Definition at line 50 of file itkPlatformMultiThreader.h.

+ Inheritance diagram for itk::PlatformMultiThreader:
+ Collaboration diagram for itk::PlatformMultiThreader:

Classes

struct  WorkUnitInfo
 

Public Types

using ConstPointer = SmartPointer<const Self>
 
using Pointer = SmartPointer<Self>
 
using Self = PlatformMultiThreader
 
using Superclass = MultiThreaderBase
 
- Public Types inherited from itk::MultiThreaderBase
using ArrayThreadingFunctorType = std::function<void(SizeValueType)>
 
using ConstPointer = SmartPointer<const Self>
 
using Pointer = SmartPointer<Self>
 
using Self = MultiThreaderBase
 
using Superclass = Object
 
using ThreaderEnum = MultiThreaderBaseEnums::Threader
 
using ThreadingFunctorType = std::function<void(const IndexValueType index[], const SizeValueType size[])>
 
- Public Types inherited from itk::Object
using ConstPointer = SmartPointer<const Self>
 
using Pointer = SmartPointer<Self>
 
using Self = Object
 
using Superclass = LightObject
 
- Public Types inherited from itk::LightObject
using ConstPointer = SmartPointer<const Self>
 
using Pointer = SmartPointer<Self>
 
using Self = LightObject
 

Public Member Functions

virtual::itk::LightObject::Pointer CreateAnother () const
 
const char * GetNameOfClass () const override
 
void MultipleMethodExecute ()
 
void SetMaximumNumberOfThreads (ThreadIdType numberOfThreads) override
 
void SetMultipleMethod (ThreadIdType index, ThreadFunctionType, void *data)
 
void SetNumberOfWorkUnits (ThreadIdType numberOfWorkUnits) override
 
void SetSingleMethod (ThreadFunctionType, void *data) override
 
void SingleMethodExecute () override
 
ThreadIdType SpawnThread (ThreadFunctionType, void *data)
 
void TerminateThread (ThreadIdType thread_id)
 
- Public Member Functions inherited from itk::MultiThreaderBase
virtual bool GetUpdateProgress () const
 
virtual void ParallelizeArray (SizeValueType firstIndex, SizeValueType lastIndexPlus1, ArrayThreadingFunctorType aFunc, ProcessObject *filter)
 
template<unsigned int VDimension, typename TFunction>
ITK_TEMPLATE_EXPORT void ParallelizeImageRegion (const ImageRegion< VDimension > &requestedRegion, TFunction funcP, ProcessObject *filter)
 
virtual void ParallelizeImageRegion (unsigned int dimension, const IndexValueType index[], const SizeValueType size[], ThreadingFunctorType funcP, ProcessObject *filter)
 
template<unsigned int VDimension, typename TFunction>
ITK_TEMPLATE_EXPORT void ParallelizeImageRegionRestrictDirection (unsigned int restrictedDirection, const ImageRegion< VDimension > &requestedRegion, TFunction funcP, ProcessObject *filter)
 
void SetSingleMethodAndExecute (ThreadFunctionType func, void *data)
 
virtual void SetUpdateProgress (bool updates)
 
virtual ThreadIdType GetMaximumNumberOfThreads () const
 
virtual ThreadIdType GetNumberOfWorkUnits () const
 
- Public Member Functions inherited from itk::Object
unsigned long AddObserver (const EventObject &event, Command *cmd) const
 
unsigned long AddObserver (const EventObject &event, std::function< void(const EventObject &)> function) const
 
virtual void DebugOff () const
 
virtual void DebugOn () const
 
CommandGetCommand (unsigned long tag)
 
bool GetDebug () const
 
MetaDataDictionaryGetMetaDataDictionary ()
 
const MetaDataDictionaryGetMetaDataDictionary () const
 
virtual ModifiedTimeType GetMTime () const
 
virtual const TimeStampGetTimeStamp () const
 
bool HasObserver (const EventObject &event) const
 
void InvokeEvent (const EventObject &)
 
void InvokeEvent (const EventObject &) const
 
virtual void Modified () const
 
void Register () const override
 
void RemoveAllObservers ()
 
void RemoveObserver (unsigned long tag) const
 
void SetDebug (bool debugFlag) const
 
void SetReferenceCount (int) override
 
void UnRegister () const noexcept override
 
void SetMetaDataDictionary (const MetaDataDictionary &rhs)
 
void SetMetaDataDictionary (MetaDataDictionary &&rrhs)
 
virtual void SetObjectName (std::string _arg)
 
virtual const std::string & GetObjectName () const
 
- Public Member Functions inherited from itk::LightObject
Pointer Clone () const
 
virtual void Delete ()
 
virtual int GetReferenceCount () const
 
void Print (std::ostream &os, Indent indent=0) const
 

Static Public Member Functions

static Pointer New ()
 
- Static Public Member Functions inherited from itk::MultiThreaderBase
static Pointer New ()
 
static ThreaderEnum ThreaderTypeFromString (std::string threaderString)
 
static std::string ThreaderTypeToString (ThreaderEnum threader)
 
static void SetGlobalMaximumNumberOfThreads (ThreadIdType val)
 
static ThreadIdType GetGlobalMaximumNumberOfThreads ()
 
static void SetGlobalDefaultUseThreadPool (const bool GlobalDefaultUseThreadPool)
 
static bool GetGlobalDefaultUseThreadPool ()
 
static void SetGlobalDefaultThreader (ThreaderEnum threaderType)
 
static ThreaderEnum GetGlobalDefaultThreader ()
 
static void SetGlobalDefaultNumberOfThreads (ThreadIdType val)
 
static ThreadIdType GetGlobalDefaultNumberOfThreads ()
 
- Static Public Member Functions inherited from itk::Object
static bool GetGlobalWarningDisplay ()
 
static void GlobalWarningDisplayOff ()
 
static void GlobalWarningDisplayOn ()
 
static Pointer New ()
 
static void SetGlobalWarningDisplay (bool val)
 
- Static Public Member Functions inherited from itk::LightObject
static void BreakOnError ()
 
static Pointer New ()
 

Protected Member Functions

 PlatformMultiThreader ()
 
void PrintSelf (std::ostream &os, Indent indent) const override
 
 ~PlatformMultiThreader () override
 
- Protected Member Functions inherited from itk::MultiThreaderBase
 MultiThreaderBase ()
 
 ~MultiThreaderBase () override
 
- Protected Member Functions inherited from itk::Object
 Object ()
 
bool PrintObservers (std::ostream &os, Indent indent) const
 
virtual void SetTimeStamp (const TimeStamp &timeStamp)
 
 ~Object () override
 
- Protected Member Functions inherited from itk::LightObject
virtual LightObject::Pointer InternalClone () const
 
 LightObject ()
 
virtual void PrintHeader (std::ostream &os, Indent indent) const
 
virtual void PrintTrailer (std::ostream &os, Indent indent) const
 
virtual ~LightObject ()
 

Private Member Functions

ThreadProcessIdType SpawnDispatchSingleMethodThread (WorkUnitInfo *)
 
void SpawnWaitForSingleMethodThread (ThreadProcessIdType)
 

Private Attributes

int m_SpawnedThreadActiveFlag [ITK_MAX_THREADS] {}
 
std::shared_ptr< std::mutex > m_SpawnedThreadActiveFlagMutex [ITK_MAX_THREADS] {}
 
WorkUnitInfo m_SpawnedThreadInfoArray [ITK_MAX_THREADS] {}
 
ThreadProcessIdType m_SpawnedThreadProcessID [ITK_MAX_THREADS] {}
 
WorkUnitInfo m_ThreadInfoArray [ITK_MAX_THREADS] {}
 

Friends

class ProcessObject
 

Additional Inherited Members

- Static Protected Member Functions inherited from itk::MultiThreaderBase
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ParallelizeArrayHelper (void *arg)
 
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ParallelizeImageRegionHelper (void *arg)
 
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION SingleMethodProxy (void *arg)
 
- Protected Attributes inherited from itk::MultiThreaderBase
ThreadIdType m_MaximumNumberOfThreads {}
 
ThreadIdType m_NumberOfWorkUnits {}
 
void * m_SingleData { nullptr }
 
ThreadFunctionType m_SingleMethod { nullptr }
 
- Protected Attributes inherited from itk::LightObject
std::atomic< int > m_ReferenceCount {}
 

Member Typedef Documentation

◆ ConstPointer

◆ Pointer

◆ Self

Standard class type aliases.

Definition at line 56 of file itkPlatformMultiThreader.h.

◆ Superclass

Constructor & Destructor Documentation

◆ PlatformMultiThreader()

itk::PlatformMultiThreader::PlatformMultiThreader ( )
protected

Referenced by GetNameOfClass().

◆ ~PlatformMultiThreader()

itk::PlatformMultiThreader::~PlatformMultiThreader ( )
overrideprotected

Member Function Documentation

◆ CreateAnother()

virtual::itk::LightObject::Pointer itk::PlatformMultiThreader::CreateAnother ( ) const
virtual

Create an object from an instance, potentially deferring to a factory. This method allows you to create an instance of an object that is exactly the same type as the referring object. This is useful in cases where an object has been cast back to a base class.

Reimplemented from itk::Object.

◆ GetNameOfClass()

const char * itk::PlatformMultiThreader::GetNameOfClass ( ) const
overridevirtual

◆ MultipleMethodExecute()

void itk::PlatformMultiThreader::MultipleMethodExecute ( )

Execute the MultipleMethods (as define by calling SetMultipleMethod for each of the required m_NumberOfWorkUnits methods) using m_NumberOfWorkUnits threads. As a side effect the m_NumberOfWorkUnits will be checked against the current m_GlobalMaximumNumberOfThreads and clamped if necessary.

◆ New()

static Pointer itk::PlatformMultiThreader::New ( )
static

Method for creation through the object factory.

◆ PrintSelf()

void itk::PlatformMultiThreader::PrintSelf ( std::ostream & os,
Indent indent ) const
overrideprotectedvirtual

Methods invoked by Print() to print information about the object including superclasses. Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.

Reimplemented from itk::MultiThreaderBase.

◆ SetMaximumNumberOfThreads()

void itk::PlatformMultiThreader::SetMaximumNumberOfThreads ( ThreadIdType numberOfThreads)
overridevirtual

Get/Set the number of threads to use. It will be clamped to the range [ 1, m_GlobalMaximumNumberOfThreads ], so the caller of this method should check that the requested number of threads was accepted.

Reimplemented from itk::MultiThreaderBase.

◆ SetMultipleMethod()

void itk::PlatformMultiThreader::SetMultipleMethod ( ThreadIdType index,
ThreadFunctionType ,
void * data )

Set the MultipleMethod at the given index to f() and the UserData field of the WorkUnitInfo that is passed to it will be data.

◆ SetNumberOfWorkUnits()

void itk::PlatformMultiThreader::SetNumberOfWorkUnits ( ThreadIdType numberOfWorkUnits)
overridevirtual

Get/Set the number of work units to create. It might be clamped to the range [ 1, SomeMaximumNumber ], so the caller of this method should check that the requested number of work units was accepted.

Reimplemented from itk::MultiThreaderBase.

◆ SetSingleMethod()

void itk::PlatformMultiThreader::SetSingleMethod ( ThreadFunctionType ,
void * data )
overridevirtual

Set the SingleMethod to f() and the UserData field of the WorkUnitInfo that is passed to it will be data. This method (and all the methods passed to SetMultipleMethod) must be of type itkThreadFunctionType and must take a single argument of type void *.

Implements itk::MultiThreaderBase.

◆ SingleMethodExecute()

void itk::PlatformMultiThreader::SingleMethodExecute ( )
overridevirtual

Execute the SingleMethod (as define by SetSingleMethod) using m_NumberOfWorkUnits threads. As a side effect the m_NumberOfWorkUnits will be checked against the current m_GlobalMaximumNumberOfThreads and clamped if necessary.

Implements itk::MultiThreaderBase.

◆ SpawnDispatchSingleMethodThread()

ThreadProcessIdType itk::PlatformMultiThreader::SpawnDispatchSingleMethodThread ( WorkUnitInfo * )
private

spawn a new thread for the SingleMethod

◆ SpawnThread()

ThreadIdType itk::PlatformMultiThreader::SpawnThread ( ThreadFunctionType ,
void * data )

Create a new thread for the given function. Return a thread id which is a number between 0 and ITK_MAX_THREADS - 1. This id should be used to kill the thread at a later time. Deprecated. Use C++11 thread support instead.

◆ SpawnWaitForSingleMethodThread()

void itk::PlatformMultiThreader::SpawnWaitForSingleMethodThread ( ThreadProcessIdType )
private

wait for a thread in the threadpool to finish work

◆ TerminateThread()

void itk::PlatformMultiThreader::TerminateThread ( ThreadIdType thread_id)

Terminate the thread that was created with a SpawnThreadExecute() Deprecated. Use C++11 thread support instead.

Friends And Related Symbol Documentation

◆ ProcessObject

friend class ProcessObject
friend

Friends of Multithreader. ProcessObject is a friend so that it can call PrintSelf() on its Multithreader.

Friends of DataObject

Definition at line 191 of file itkPlatformMultiThreader.h.

References ProcessObject.

Referenced by ProcessObject.

Member Data Documentation

◆ m_SpawnedThreadActiveFlag

int itk::PlatformMultiThreader::m_SpawnedThreadActiveFlag[ITK_MAX_THREADS] {}
private

Storage of MutexFunctions and ints used to control spawned threads and the spawned thread ids.

Definition at line 168 of file itkPlatformMultiThreader.h.

◆ m_SpawnedThreadActiveFlagMutex

std::shared_ptr<std::mutex> itk::PlatformMultiThreader::m_SpawnedThreadActiveFlagMutex[ITK_MAX_THREADS] {}
private

Definition at line 169 of file itkPlatformMultiThreader.h.

◆ m_SpawnedThreadInfoArray

WorkUnitInfo itk::PlatformMultiThreader::m_SpawnedThreadInfoArray[ITK_MAX_THREADS] {}
private

Definition at line 171 of file itkPlatformMultiThreader.h.

◆ m_SpawnedThreadProcessID

ThreadProcessIdType itk::PlatformMultiThreader::m_SpawnedThreadProcessID[ITK_MAX_THREADS] {}
private

Definition at line 170 of file itkPlatformMultiThreader.h.

◆ m_ThreadInfoArray

WorkUnitInfo itk::PlatformMultiThreader::m_ThreadInfoArray[ITK_MAX_THREADS] {}
private

An array of thread info containing a thread id (0, 1, 2, .. ITK_MAX_THREADS-1), the thread count, and a pointer to void so that user data can be passed to each thread.

Definition at line 164 of file itkPlatformMultiThreader.h.


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