ITK  5.2.0
Insight Toolkit
itkDomainThreader.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkDomainThreader_h
19 #define itkDomainThreader_h
20 
21 #include "itkObject.h"
22 #include "itkMultiThreaderBase.h"
23 
24 namespace itk
25 {
26 
65 template <typename TDomainPartitioner, typename TAssociate>
66 class ITK_TEMPLATE_EXPORT DomainThreader : public Object
67 {
68 public:
69  ITK_DISALLOW_COPY_AND_MOVE(DomainThreader);
70 
73  using Superclass = Object;
76 
77  using DomainPartitionerType = TDomainPartitioner;
79 
80  using AssociateType = TAssociate;
81 
83  itkTypeMacro(DomainThreader, Object);
84 
90  void
91  Execute(AssociateType * enclosingClass, const DomainType & completeDomain);
92 
94  itkSetObjectMacro(DomainPartitioner, DomainPartitionerType);
95  itkGetModifiableObjectMacro(DomainPartitioner, DomainPartitionerType);
97 
100  itkGetConstMacro(NumberOfWorkUnitsUsed, ThreadIdType);
101 
104  GetMultiThreader() const;
105 
110  itkSetClampMacro(NumberOfWorkUnits, ThreadIdType, 1, ITK_MAX_THREADS);
111  itkGetConstMacro(NumberOfWorkUnits, ThreadIdType);
113 
120  {
121  return this->m_MultiThreader->GetMaximumNumberOfThreads();
122  }
123  void
124  SetMaximumNumberOfThreads(const ThreadIdType threads);
126 
127 protected:
128  DomainThreader();
129  ~DomainThreader() override = default;
130 
133  virtual void
134  DetermineNumberOfWorkUnitsUsed();
135 
139  virtual void
141  {}
142 
151  virtual void
152  ThreadedExecution(const DomainType & subdomain, const ThreadIdType threadId) = 0;
153 
157  virtual void
159  {}
160 
161  itkSetObjectMacro(MultiThreader, MultiThreaderBase);
162 
167  ThreaderCallback(void * arg);
168 
170 
171 private:
172  void
173  StartThreadingSequence();
174 
177  {
179  };
180 
185  ThreadIdType m_NumberOfWorkUnitsUsed{ 0 };
190 };
191 
192 } // namespace itk
193 
194 #ifndef ITK_MANUAL_INSTANTIATION
195 # include "itkDomainThreader.hxx"
196 #endif
197 
198 #endif
itk::MultiThreaderBase
A class for performing multithreaded execution.
Definition: itkMultiThreaderBase.h:105
itk::DomainThreader< ThreadedIndexedContainerPartitioner, TJointHistogramMetric >::AssociateType
TJointHistogramMetric AssociateType
Definition: itkDomainThreader.h:80
itk::DomainThreader::GetMaximumNumberOfThreads
ThreadIdType GetMaximumNumberOfThreads() const
Definition: itkDomainThreader.h:119
itk::DomainThreader::m_MultiThreader
MultiThreaderBase::Pointer m_MultiThreader
Definition: itkDomainThreader.h:189
itk::ThreadedIndexedContainerPartitioner
Partitions an indexed container.
Definition: itkThreadedIndexedContainerPartitioner.h:45
itk::SmartPointer< Self >
itk::ThreadIdType
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
itk::ITK_MAX_THREADS
constexpr std::vcl_size_t ITK_MAX_THREADS
Definition: itkThreadSupport.h:74
itk::ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
itk::ITK_THREAD_RETURN_TYPE ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
Definition: itkThreadSupport.h:82
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::DomainThreader::m_DomainPartitioner
DomainPartitionerType::Pointer m_DomainPartitioner
Definition: itkDomainThreader.h:187
itk::DomainThreader::ThreadStruct::domainThreader
DomainThreader * domainThreader
Definition: itkDomainThreader.h:178
itk::DomainThreader::m_CompleteDomain
DomainType m_CompleteDomain
Definition: itkDomainThreader.h:188
itk::DomainThreader< ThreadedIndexedContainerPartitioner, TJointHistogramMetric >::DomainType
typename DomainPartitionerType::DomainType DomainType
Definition: itkDomainThreader.h:78
itk::DomainThreader::AfterThreadedExecution
virtual void AfterThreadedExecution()
Definition: itkDomainThreader.h:158
itk::DomainThreader
Multi-threaded processing on a domain by processing sub-domains per thread.
Definition: itkDomainThreader.h:66
itk::DomainThreader::ThreadStruct
Definition: itkDomainThreader.h:176
itkObject.h
itk::DomainThreader::m_NumberOfWorkUnits
ThreadIdType m_NumberOfWorkUnits
Definition: itkDomainThreader.h:186
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itkMultiThreaderBase.h
itk::DomainThreader::m_Associate
AssociateType * m_Associate
Definition: itkDomainThreader.h:169
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::ThreadedIndexedContainerPartitioner::DomainType
Superclass::DomainType DomainType
Definition: itkThreadedIndexedContainerPartitioner.h:63
itk::DomainThreader::BeforeThreadedExecution
virtual void BeforeThreadedExecution()
Definition: itkDomainThreader.h:140