ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkDomainThreader.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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_ASSIGN(DomainThreader);
70 
73  using Superclass = Object;
76 
77  using DomainPartitionerType = TDomainPartitioner;
79 
80  using AssociateType = TAssociate;
81 
83  itkTypeMacro( DomainThreader, Object );
84 
90  void Execute( AssociateType * enclosingClass, const DomainType & domain );
91 
93  itkSetObjectMacro( DomainPartitioner, DomainPartitionerType );
94  itkGetModifiableObjectMacro( DomainPartitioner, DomainPartitionerType );
96 
99  itkGetConstMacro( NumberOfWorkUnitsUsed, ThreadIdType );
100 
102  MultiThreaderBase * GetMultiThreader() const;
103 
108  itkSetClampMacro(NumberOfWorkUnits, ThreadIdType, 1, ITK_MAX_THREADS);
109  itkGetConstMacro(NumberOfWorkUnits, ThreadIdType);
111 
117  {
118  return this->m_MultiThreader->GetMaximumNumberOfThreads();
119  }
120  void SetMaximumNumberOfThreads(const ThreadIdType threads);
122 
123 protected:
124  DomainThreader();
125  ~DomainThreader() override = default;
126 
129  virtual void DetermineNumberOfWorkUnitsUsed();
130 
134  virtual void BeforeThreadedExecution(){}
135 
144  virtual void ThreadedExecution( const DomainType& subdomain,
145  const ThreadIdType threadId ) = 0;
146 
150  virtual void AfterThreadedExecution(){}
151 
152  itkSetObjectMacro( MultiThreader, MultiThreaderBase );
153 
157  static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ThreaderCallback( void *arg );
158 
160 
161 private:
162  void StartThreadingSequence();
163 
166  {
168  };
169 
174  ThreadIdType m_NumberOfWorkUnitsUsed{0};
179 };
180 
181 }
182 
183 #ifndef ITK_MANUAL_INSTANTIATION
184 #include "itkDomainThreader.hxx"
185 #endif
186 
187 #endif
virtual void BeforeThreadedExecution()
Light weight base class for most itk classes.
Multi-threaded processing on a domain by processing sub-domains per thread.
virtual void AfterThreadedExecution()
itk::ITK_THREAD_RETURN_TYPE ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
AssociateType * m_Associate
constexpr std::vcl_size_t ITK_MAX_THREADS
DomainPartitionerType::Pointer m_DomainPartitioner
A class for performing multithreaded execution.
ThreadIdType m_NumberOfWorkUnits
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
ThreadIdType GetMaximumNumberOfThreads() const
Base class for most ITK classes.
Definition: itkObject.h:60
MultiThreaderBase::Pointer m_MultiThreader