39 #include "vtkCommonCoreModule.h"
47 #include <type_traits>
49 #ifndef DOXYGEN_SHOULD_SKIP_THIS
57 class vtkSMPTools_Has_Initialize
59 typedef char (&no_type)[1];
60 typedef char (&yes_type)[2];
61 template <
typename U,
void (U::*)()>
66 static yes_type check(V<U, &U::Initialize>*);
68 static no_type check(...);
71 static bool const value =
sizeof(check<T>(
nullptr)) ==
sizeof(yes_type);
75 class vtkSMPTools_Has_Initialize_const
77 typedef char (&no_type)[1];
78 typedef char (&yes_type)[2];
79 template <
typename U,
void (U::*)() const>
84 static yes_type check(V<U, &U::Initialize>*);
86 static no_type check(...);
89 static bool const value =
sizeof(check<T>(0)) ==
sizeof(yes_type);
92 template <
typename Functor,
bool Init>
93 struct vtkSMPTools_FunctorInternal;
95 template <
typename Functor>
96 struct vtkSMPTools_FunctorInternal<Functor, false>
99 vtkSMPTools_FunctorInternal(Functor& f)
107 SMPToolsAPI.For(first, last, grain, *
this);
109 vtkSMPTools_FunctorInternal<Functor, false>& operator=(
110 const vtkSMPTools_FunctorInternal<Functor, false>&);
111 vtkSMPTools_FunctorInternal<Functor, false>(
const vtkSMPTools_FunctorInternal<Functor, false>&);
114 template <
typename Functor>
115 struct vtkSMPTools_FunctorInternal<Functor, true>
119 vtkSMPTools_FunctorInternal(Functor& f)
126 unsigned char& inited = this->Initialized.
Local();
129 this->F.Initialize();
132 this->F(first, last);
137 SMPToolsAPI.For(first, last, grain, *
this);
140 vtkSMPTools_FunctorInternal<Functor, true>& operator=(
141 const vtkSMPTools_FunctorInternal<Functor, true>&);
142 vtkSMPTools_FunctorInternal<Functor, true>(
const vtkSMPTools_FunctorInternal<Functor, true>&);
145 template <
typename Functor>
146 class vtkSMPTools_Lookup_For
151 typedef vtkSMPTools_FunctorInternal<Functor, init>
type;
154 template <
typename Functor>
155 class vtkSMPTools_Lookup_For<Functor const>
160 typedef vtkSMPTools_FunctorInternal<Functor const, init>
type;
163 template <
typename Iterator,
typename Functor,
bool Init>
164 struct vtkSMPTools_RangeFunctor;
166 template <
typename Iterator,
typename Functor>
167 struct vtkSMPTools_RangeFunctor<Iterator, Functor, false>
171 vtkSMPTools_RangeFunctor(Iterator& begin, Functor& f)
178 Iterator itFirst(Begin);
179 std::advance(itFirst, first);
180 Iterator itLast(itFirst);
181 std::advance(itLast, last - first);
182 this->F(itFirst, itLast);
186 template <
typename Iterator,
typename Functor>
187 struct vtkSMPTools_RangeFunctor<Iterator, Functor, true>
191 vtkSMPTools_RangeFunctor(Iterator& begin, Functor& f)
196 void Initialize() { this->F.Initialize(); }
199 Iterator itFirst(Begin);
200 std::advance(itFirst, first);
201 Iterator itLast(itFirst);
202 std::advance(itLast, last - first);
203 this->F(itFirst, itLast);
205 void Reduce() { this->F.Reduce(); }
208 template <
typename Iterator,
typename Functor>
209 class vtkSMPTools_Lookup_RangeFor
214 typedef vtkSMPTools_RangeFunctor<Iterator, Functor, init>
type;
217 template <
typename Iterator,
typename Functor>
218 class vtkSMPTools_Lookup_RangeFor<Iterator, Functor const>
223 typedef vtkSMPTools_RangeFunctor<Iterator, Functor const, init>
type;
226 template <
typename T>
231 #endif // DOXYGEN_SHOULD_SKIP_THIS
246 template <
typename Functor>
250 fi.For(first, last, grain);
253 template <
typename Functor>
257 fi.For(first, last, grain);
271 template <
typename Functor>
277 template <
typename Functor>
320 template <
typename Iter,
typename Functor>
321 static vtk::detail::smp::resolvedNotInt<Iter>
For(
322 Iter begin, Iter end,
vtkIdType grain, Functor& f)
329 template <
typename Iter,
typename Functor>
330 static vtk::detail::smp::resolvedNotInt<Iter>
For(
331 Iter begin, Iter end,
vtkIdType grain, Functor
const& f)
373 template <
typename Iter,
typename Functor>
374 static vtk::detail::smp::resolvedNotInt<Iter>
For(Iter begin, Iter end, Functor& f)
379 template <
typename Iter,
typename Functor>
380 static vtk::detail::smp::resolvedNotInt<Iter>
For(Iter begin, Iter end, Functor
const& f)
389 static const char* GetBackend();
402 static bool SetBackend(
const char* backend);
419 static void Initialize(
int numThreads = 0);
427 static int GetEstimatedNumberOfThreads();
440 static void SetNestedParallelism(
bool isNested);
445 static bool GetNestedParallelism();
450 static bool IsParallelScope();
461 int MaxNumberOfThreads = 0;
463 bool NestedParallelism =
true;
467 : MaxNumberOfThreads(maxNumberOfThreads)
475 : NestedParallelism(nestedParallelism)
479 : MaxNumberOfThreads(maxNumberOfThreads)
481 , NestedParallelism(nestedParallelism)
484 #ifndef DOXYGEN_SHOULD_SKIP_THIS
486 : MaxNumberOfThreads(API.GetInternalDesiredNumberOfThread())
487 , Backend(API.GetBackend())
488 , NestedParallelism(API.GetNestedParallelism())
491 #endif // DOXYGEN_SHOULD_SKIP_THIS
505 template <
typename T>
527 template <
typename InputIt,
typename OutputIt,
typename Functor>
528 static void Transform(InputIt inBegin, InputIt inEnd, OutputIt outBegin, Functor transform)
531 SMPToolsAPI.Transform(inBegin, inEnd, outBegin, transform);
550 template <
typename InputIt1,
typename InputIt2,
typename OutputIt,
typename Functor>
552 InputIt1 inBegin1, InputIt1 inEnd, InputIt2 inBegin2, OutputIt outBegin, Functor transform)
555 SMPToolsAPI.Transform(inBegin1, inEnd, inBegin2, outBegin, transform);
572 template <
typename Iterator,
typename T>
573 static void Fill(Iterator begin, Iterator end,
const T&
value)
576 SMPToolsAPI.Fill(begin, end, value);
584 template <
typename RandomAccessIterator>
585 static void Sort(RandomAccessIterator begin, RandomAccessIterator end)
588 SMPToolsAPI.Sort(begin, end);
597 template <
typename RandomAccessIterator,
typename Compare>
598 static void Sort(RandomAccessIterator begin, RandomAccessIterator end, Compare comp)
601 SMPToolsAPI.Sort(begin, end, comp);
T & Local()
This needs to be called mainly within a threaded execution path.
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
Thread local storage for VTK objects.