39#include "vtkCommonCoreModule.h"
49#ifndef DOXYGEN_SHOULD_SKIP_THIS
57class 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);
75class 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);
92template <
typename Functor,
bool Init>
93struct vtkSMPTools_FunctorInternal;
95template <
typename Functor>
96struct vtkSMPTools_FunctorInternal<Functor, false>
99 vtkSMPTools_FunctorInternal(Functor& f)
106 auto& SMPToolsAPI = vtkSMPToolsAPI::GetInstance();
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>&);
114template <
typename Functor>
115struct 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);
136 auto& SMPToolsAPI = vtkSMPToolsAPI::GetInstance();
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>&);
145template <
typename Functor>
146class vtkSMPTools_Lookup_For
148 static bool const init = vtkSMPTools_Has_Initialize<Functor>::value;
151 typedef vtkSMPTools_FunctorInternal<Functor, init>
type;
154template <
typename Functor>
155class vtkSMPTools_Lookup_For<Functor const>
157 static bool const init = vtkSMPTools_Has_Initialize_const<Functor>::value;
160 typedef vtkSMPTools_FunctorInternal<Functor const, init>
type;
163template <
typename Iterator,
typename Functor,
bool Init>
164struct vtkSMPTools_RangeFunctor;
166template <
typename Iterator,
typename Functor>
167struct 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);
186template <
typename Iterator,
typename Functor>
187struct 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(); }
208template <
typename Iterator,
typename Functor>
209class vtkSMPTools_Lookup_RangeFor
211 static bool const init = vtkSMPTools_Has_Initialize<Functor>::value;
214 typedef vtkSMPTools_RangeFunctor<Iterator, Functor, init>
type;
217template <
typename Iterator,
typename Functor>
218class vtkSMPTools_Lookup_RangeFor<Iterator, Functor const>
220 static bool const init = vtkSMPTools_Has_Initialize_const<Functor>::value;
223 typedef vtkSMPTools_RangeFunctor<Iterator, Functor const, init>
type;
227using resolvedNotInt =
typename std::enable_if<!std::is_integral<T>::value,
void>::type;
246 template <
typename Functor>
249 typename vtk::detail::smp::vtkSMPTools_Lookup_For<Functor>::type fi(f);
250 fi.For(first, last, grain);
253 template <
typename Functor>
256 typename vtk::detail::smp::vtkSMPTools_Lookup_For<Functor const>::type fi(f);
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)
324 vtkIdType size = std::distance(begin, end);
325 typename vtk::detail::smp::vtkSMPTools_Lookup_RangeFor<Iter, Functor>::type fi(begin, 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)
333 vtkIdType size = std::distance(begin, end);
334 typename vtk::detail::smp::vtkSMPTools_Lookup_RangeFor<Iter, Functor const>::type fi(begin, 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)
461 int MaxNumberOfThreads = 0;
463 bool NestedParallelism =
true;
467 : MaxNumberOfThreads(maxNumberOfThreads)
475 : NestedParallelism(nestedParallelism)
478 Config(
int maxNumberOfThreads, std::string backend,
bool 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())
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);
Thread local storage for VTK objects.
T & Local()
This needs to be called mainly within a threaded execution path.
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.