28 #ifndef itkMultiThreaderBase_h
29 #define itkMultiThreaderBase_h
58 struct MultiThreaderBaseGlobals;
81 virtual void SetMaximumNumberOfThreads(
ThreadIdType numberOfThreads );
82 itkGetConstMacro( MaximumNumberOfThreads,
ThreadIdType );
88 virtual void SetNumberOfWorkUnits(
ThreadIdType numberOfWorkUnits );
97 static void SetGlobalMaximumNumberOfThreads(
ThreadIdType val);
106 itkLegacyMacro(
static void SetGlobalDefaultUseThreadPool(
const bool GlobalDefaultUseThreadPool ));
107 itkLegacyMacro(
static bool GetGlobalDefaultUseThreadPool( ));
112 enum ThreaderType { Platform = 0, First = Platform, Pool, TBB, Last = TBB, Unknown = -1 };
115 static ThreaderType ThreaderTypeFromString(std::string threaderString);
122 case ThreaderType::Platform:
125 case ThreaderType::Pool:
128 case ThreaderType::TBB:
131 case ThreaderType::Unknown:
150 static void SetGlobalDefaultThreader(ThreaderType threaderType);
151 static ThreaderType GetGlobalDefaultThreader();
158 static void SetGlobalDefaultNumberOfThreads(
ThreadIdType val);
162 #if !defined( ITK_LEGACY_REMOVE )
165 itkLegacyMacro(
virtual void SetNumberOfThreads(
ThreadIdType numberOfThreads ) )
167 this->SetMaximumNumberOfThreads( numberOfThreads );
168 this->SetNumberOfWorkUnits( this->GetMaximumNumberOfThreads() );
170 itkLegacyMacro(
virtual ThreadIdType GetNumberOfThreads() )
172 return this->GetNumberOfWorkUnits();
184 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
185 ITK_GCC_PRAGMA_DIAG_PUSH()
187 ITK_GCC_PRAGMA_DIAG(ignored
"-Wattributes")
188 INTEL_PRAGMA_WARN_PUSH
189 INTEL_SUPPRESS_warning_1292
191 CLANG_SUPPRESS_Wc__14_extensions
192 struct [[deprecated( "Use WorkUnitInfo, ThreadInfoStruct is deprecated since ITK 5.0" )]] ThreadInfoStruct
194 INTEL_PRAGMA_WARN_POP
200 enum { SUCCESS, ITK_EXCEPTION, ITK_PROCESS_ABORTED_EXCEPTION, STD_EXCEPTION, UNKNOWN } ThreadExitCode;
202 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
203 ITK_GCC_PRAGMA_DIAG_POP()
205 ITK_GCC_PRAGMA_DIAG(warning
"-Wattributes")
207 #endif //ITK_LEGACY_REMOVE
236 virtual void SingleMethodExecute() = 0;
244 template <
unsigned int VDimension>
266 template<
unsigned int VDimension>
271 this->ParallelizeImageRegion(
278 for (
unsigned int d = 0; d < VDimension; ++d)
292 template<
unsigned int VDimension>
301 funcP(requestedRegion);
306 constexpr
unsigned int SplitDimension = (VDimension-1) ? VDimension-1 : VDimension;
310 SplitRegionType splitRegion;
311 for(
unsigned int splitDimension = 0, dimension = 0; dimension < VDimension; ++dimension )
313 if( dimension == restrictedDirection )
317 splitRegion.
SetIndex( splitDimension, requestedRegion.
GetIndex( dimension ) );
318 splitRegion.SetSize( splitDimension, requestedRegion.
GetSize( dimension ) );
322 this->ParallelizeImageRegion(
324 splitRegion.GetIndex().m_InternalArray,
325 splitRegion.GetSize().m_InternalArray,
329 restrictedRequestedRegion.
SetIndex( restrictedDirection, requestedRegion.
GetIndex( restrictedDirection ) );
330 restrictedRequestedRegion.
SetSize( restrictedDirection, requestedRegion.
GetSize( restrictedDirection ) );
331 for(
unsigned int splitDimension = 0, dimension = 0; dimension < VDimension; ++dimension )
333 if( dimension == restrictedDirection )
337 restrictedRequestedRegion.
SetIndex( dimension, index[splitDimension] );
338 restrictedRequestedRegion.
SetSize( dimension, size[splitDimension] );
341 funcP( restrictedRequestedRegion );
349 virtual void ParallelizeImageRegion(
350 unsigned int dimension,
353 ThreadingFunctorType funcP,
358 static void HandleFilterProgress(
ProcessObject *filter,
float progress = -1.0f);
363 void PrintSelf(std::ostream & os,
Indent indent)
const override;
430 static ThreadIdType GetGlobalDefaultNumberOfThreadsByPlatform();
434 ITKCommon_EXPORT std::ostream&
operator << (std::ostream& os,
void SetSize(const SizeType &size)
void(* ThreadFunctionType)(void *)
Light weight base class for most itk classes.
const IndexType & GetIndex() const
const SizeValueType * size
static void HandleFilterProgress(ProcessObject *filter, float progress=-1.0f)
ThreadIdType m_MaximumNumberOfThreads
unsigned long SizeValueType
ThreadFunctionType ThreadFunction
SizeValueType m_InternalArray[VDimension]
static MultiThreaderBaseGlobals * m_PimplGlobals
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
std::atomic< SizeValueType > progress
ThreadFunctionType m_SingleMethod
itk::ITK_THREAD_RETURN_TYPE ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
std::thread::id callingThread
class ITK_FORWARD_EXPORT ProcessObject
std::function< void(SizeValueType) > ArrayThreadingFunctorType
std::function< void(const IndexValueType index[], const SizeValueType size[])> ThreadingFunctorType
IndexValueType m_InternalArray[VDimension]
#define itkGetGlobalDeclarationMacro(Type, VarName)
const IndexValueType * index
const SizeValueType firstIndex
static std::string ThreaderTypeToString(ThreaderType threader)
signed long IndexValueType
ThreadingFunctorType functor
ITK_TEMPLATE_EXPORT void ParallelizeImageRegionRestrictDirection(unsigned int restrictedDirection, const ImageRegion< VDimension > &requestedRegion, TemplatedThreadingFunctorType< VDimension > funcP, ProcessObject *filter)
const SizeType & GetSize() const
A class for performing multithreaded execution.
std::function< void(const ImageRegion< VDimension > &)> TemplatedThreadingFunctorType
ThreadIdType m_NumberOfWorkUnits
unsigned int ThreadIdType
ArrayThreadingFunctorType functor
std::atomic< SizeValueType > pixelProgress
ThreadIdType NumberOfWorkUnits
std::thread::id callingThread
Control indentation during Print() invocation.
Base class for most ITK classes.
void SetIndex(const IndexType &index)
ITK_TEMPLATE_EXPORT void ParallelizeImageRegion(const ImageRegion< VDimension > &requestedRegion, TemplatedThreadingFunctorType< VDimension > funcP, ProcessObject *filter)
const SizeValueType lastIndexPlus1