4 #ifndef vtkSMPToolsAPI_h
5 #define vtkSMPToolsAPI_h
7 #include "vtkCommonCoreModule.h"
15 #if VTK_SMP_ENABLE_SEQUENTIAL
16 #include "SMP/Sequential/vtkSMPToolsImpl.txx"
18 #if VTK_SMP_ENABLE_STDTHREAD
19 #include "SMP/STDThread/vtkSMPToolsImpl.txx"
21 #if VTK_SMP_ENABLE_TBB
22 #include "SMP/TBB/vtkSMPToolsImpl.txx"
24 #if VTK_SMP_ENABLE_OPENMP
25 #include "SMP/OpenMP/vtkSMPToolsImpl.txx"
34 VTK_ABI_NAMESPACE_BEGIN
48 const char* GetBackend();
51 bool SetBackend(
const char*
type);
54 void Initialize(
int numThreads = 0);
57 int GetEstimatedNumberOfThreads();
60 int GetEstimatedDefaultNumberOfThreads();
63 void SetNestedParallelism(
bool isNested);
66 bool GetNestedParallelism();
69 bool IsParallelScope();
72 bool GetSingleThread();
78 template <
typename Config,
typename T>
81 const Config oldConfig(*
this);
96 template <
typename FunctorInternal>
99 switch (this->ActivatedBackend)
102 this->SequentialBackend->For(first, last, grain, fi);
105 this->STDThreadBackend->For(first, last, grain, fi);
108 this->TBBBackend->For(first, last, grain, fi);
111 this->OpenMPBackend->For(first, last, grain, fi);
117 template <
typename InputIt,
typename OutputIt,
typename Functor>
118 void Transform(InputIt inBegin, InputIt inEnd, OutputIt outBegin, Functor& transform)
120 switch (this->ActivatedBackend)
123 this->SequentialBackend->Transform(inBegin, inEnd, outBegin, transform);
126 this->STDThreadBackend->Transform(inBegin, inEnd, outBegin, transform);
129 this->TBBBackend->Transform(inBegin, inEnd, outBegin, transform);
132 this->OpenMPBackend->Transform(inBegin, inEnd, outBegin, transform);
138 template <
typename InputIt1,
typename InputIt2,
typename OutputIt,
typename Functor>
140 InputIt1 inBegin1, InputIt1 inEnd, InputIt2 inBegin2, OutputIt outBegin, Functor& transform)
142 switch (this->ActivatedBackend)
145 this->SequentialBackend->Transform(inBegin1, inEnd, inBegin2, outBegin, transform);
148 this->STDThreadBackend->Transform(inBegin1, inEnd, inBegin2, outBegin, transform);
151 this->TBBBackend->Transform(inBegin1, inEnd, inBegin2, outBegin, transform);
154 this->OpenMPBackend->Transform(inBegin1, inEnd, inBegin2, outBegin, transform);
160 template <
typename Iterator,
typename T>
163 switch (this->ActivatedBackend)
166 this->SequentialBackend->Fill(begin, end, value);
169 this->STDThreadBackend->Fill(begin, end, value);
172 this->TBBBackend->Fill(begin, end, value);
175 this->OpenMPBackend->Fill(begin, end, value);
181 template <
typename RandomAccessIterator>
182 void Sort(RandomAccessIterator begin, RandomAccessIterator end)
184 switch (this->ActivatedBackend)
187 this->SequentialBackend->Sort(begin, end);
190 this->STDThreadBackend->Sort(begin, end);
193 this->TBBBackend->Sort(begin, end);
196 this->OpenMPBackend->Sort(begin, end);
202 template <
typename RandomAccessIterator,
typename Compare>
203 void Sort(RandomAccessIterator begin, RandomAccessIterator end, Compare comp)
205 switch (this->ActivatedBackend)
208 this->SequentialBackend->Sort(begin, end, comp);
211 this->STDThreadBackend->Sort(begin, end, comp);
214 this->TBBBackend->Sort(begin, end, comp);
217 this->OpenMPBackend->Sort(begin, end, comp);
230 static void ClassInitialize();
231 static void ClassFinalize();
239 void RefreshNumberOfThread();
244 template <
typename Config>
247 this->Initialize(config.MaxNumberOfThreads);
248 this->SetBackend(config.Backend.c_str());
249 this->SetNestedParallelism(config.NestedParallelism);
261 int DesiredNumberOfThread = 0;
266 #if VTK_SMP_ENABLE_SEQUENTIAL
267 std::unique_ptr<vtkSMPToolsImpl<BackendType::Sequential>> SequentialBackend;
269 std::unique_ptr<vtkSMPToolsDefaultImpl> SequentialBackend;
275 #if VTK_SMP_ENABLE_STDTHREAD
276 std::unique_ptr<vtkSMPToolsImpl<BackendType::STDThread>> STDThreadBackend;
278 std::unique_ptr<vtkSMPToolsDefaultImpl> STDThreadBackend;
284 #if VTK_SMP_ENABLE_TBB
285 std::unique_ptr<vtkSMPToolsImpl<BackendType::TBB>> TBBBackend;
287 std::unique_ptr<vtkSMPToolsDefaultImpl> TBBBackend;
293 #if VTK_SMP_ENABLE_OPENMP
294 std::unique_ptr<vtkSMPToolsImpl<BackendType::OpenMP>> OpenMPBackend;
296 std::unique_ptr<vtkSMPToolsDefaultImpl> OpenMPBackend;
314 VTK_ABI_NAMESPACE_END
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkIndent &o)
static vtkSMPToolsAPIInitialize vtkSMPToolsAPIInitializer