28 #ifndef itkMultiThreaderBase_h
29 #define itkMultiThreaderBase_h
84 extern ITKCommon_EXPORT std::ostream &
86 extern ITKCommon_EXPORT std::ostream &
104 struct MultiThreaderBaseGlobals;
129 SetMaximumNumberOfThreads(
ThreadIdType numberOfThreads);
142 SetUpdateProgress(
bool updates);
143 itkGetConstMacro(UpdateProgress,
bool);
153 GetGlobalMaximumNumberOfThreads();
161 itkLegacyMacro(
static void SetGlobalDefaultUseThreadPool(
const bool GlobalDefaultUseThreadPool);)
162 itkLegacyMacro(
static bool GetGlobalDefaultUseThreadPool();)
166 #if !defined(ITK_LEGACY_REMOVE)
168 static constexpr
ThreaderEnum Platform = ThreaderEnum::Platform;
169 static constexpr
ThreaderEnum First = ThreaderEnum::First;
170 static constexpr
ThreaderEnum Pool = ThreaderEnum::Pool;
172 static constexpr
ThreaderEnum Last = ThreaderEnum::Last;
173 static constexpr
ThreaderEnum Unknown = ThreaderEnum::Unknown;
178 ThreaderTypeFromString(std::string threaderString);
186 case ThreaderEnum::Platform:
188 case ThreaderEnum::Pool:
190 case ThreaderEnum::TBB:
192 case ThreaderEnum::Unknown:
211 SetGlobalDefaultThreader(ThreaderEnum threaderType);
213 GetGlobalDefaultThreader();
223 GetGlobalDefaultNumberOfThreads();
226 #if !defined(ITK_LEGACY_REMOVE)
229 itkLegacyMacro(
virtual void SetNumberOfThreads(
ThreadIdType numberOfThreads))
231 this->SetMaximumNumberOfThreads(numberOfThreads);
232 this->SetNumberOfWorkUnits(this->GetMaximumNumberOfThreads());
234 itkLegacyMacro(
virtual ThreadIdType GetNumberOfThreads())
236 return this->GetNumberOfWorkUnits();
249 ITK_GCC_PRAGMA_DIAG_PUSH()
250 ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
251 INTEL_PRAGMA_WARN_PUSH
252 INTEL_SUPPRESS_warning_1292
254 # ifdef ITK_LEGACY_SILENT
255 struct ThreadInfoStruct
257 struct [[deprecated("Use WorkUnitInfo, ThreadInfoStruct is deprecated since ITK 5.0")]] ThreadInfoStruct
260 INTEL_PRAGMA_WARN_POP
271 ITK_PROCESS_ABORTED_EXCEPTION,
277 ITK_GCC_PRAGMA_DIAG_POP()
279 #endif // ITK_LEGACY_REMOVE
296 #if !defined(ITK_LEGACY_REMOVE)
299 static constexpr
ThreadExitCodeEnum ITK_EXCEPTION = ThreadExitCodeEnum::ITK_EXCEPTION;
301 ThreadExitCodeEnum::ITK_PROCESS_ABORTED_EXCEPTION;
302 static constexpr
ThreadExitCodeEnum STD_EXCEPTION = ThreadExitCodeEnum::STD_EXCEPTION;
313 SingleMethodExecute() = 0;
326 #ifndef ITK_FUTURE_LEGACY_REMOVE
329 template <
unsigned int VDimension>
352 template <
unsigned int VDimension,
typename TFunction>
353 ITK_TEMPLATE_EXPORT
void
356 this->ParallelizeImageRegion(
362 for (
unsigned int d = 0; d < VDimension; ++d)
376 template <
unsigned int VDimension,
typename TFunction>
377 ITK_TEMPLATE_EXPORT
void
383 if constexpr (VDimension <= 1)
387 funcP(requestedRegion);
391 constexpr
unsigned int SplitDimension = VDimension - 1;
395 for (
unsigned int splitDimension = 0, dimension = 0; dimension < VDimension; ++dimension)
397 if (dimension != restrictedDirection)
399 splitIndex[splitDimension] = requestedRegion.
GetIndex(dimension);
400 splitSize[splitDimension] = requestedRegion.
GetSize(dimension);
405 this->ParallelizeImageRegion(
407 splitIndex.m_InternalArray,
408 splitSize.m_InternalArray,
410 ImageRegion<VDimension> restrictedRequestedRegion;
411 restrictedRequestedRegion.SetIndex(restrictedDirection, requestedRegion.GetIndex(restrictedDirection));
412 restrictedRequestedRegion.SetSize(restrictedDirection, requestedRegion.GetSize(restrictedDirection));
413 for (unsigned int splitDimension = 0, dimension = 0; dimension < VDimension; ++dimension)
415 if (dimension != restrictedDirection)
417 restrictedRequestedRegion.SetIndex(dimension, index[splitDimension]);
418 restrictedRequestedRegion.SetSize(dimension, size[splitDimension]);
422 funcP(restrictedRequestedRegion);
431 ParallelizeImageRegion(
unsigned int dimension,
434 ThreadingFunctorType funcP,
439 ~MultiThreaderBase()
override;
441 PrintSelf(std::ostream & os, Indent indent)
const override;
452 ParallelizeArrayHelper(
void * arg);
464 ParallelizeImageRegionHelper(
void * arg);
486 SingleMethodProxy(
void * arg);
492 void * m_SingleData{
nullptr };
496 SetGlobalDefaultThreaderPrivate(ThreaderEnum threaderType);
498 GetGlobalDefaultThreaderPrivate();
503 std::atomic<bool> m_UpdateProgress{
true };
513 GetGlobalDefaultNumberOfThreadsByPlatform();