33#include "vtkCommonCoreModule.h"
43#ifndef DOXYGEN_SHOULD_SKIP_THIS
51class vtkSMPTools_Has_Initialize
53 typedef char (&no_type)[1];
54 typedef char (&yes_type)[2];
55 template <
typename U,
void (U::*)()>
60 static yes_type check(V<U, &U::Initialize>*);
62 static no_type check(...);
65 static bool const value =
sizeof(check<T>(
nullptr)) ==
sizeof(yes_type);
69class vtkSMPTools_Has_Initialize_const
71 typedef char (&no_type)[1];
72 typedef char (&yes_type)[2];
73 template <
typename U,
void (U::*)() const>
78 static yes_type check(V<U, &U::Initialize>*);
80 static no_type check(...);
83 static bool const value =
sizeof(check<T>(0)) ==
sizeof(yes_type);
86template <
typename Functor,
bool Init>
87struct vtkSMPTools_FunctorInternal;
89template <
typename Functor>
90struct vtkSMPTools_FunctorInternal<Functor, false>
93 vtkSMPTools_FunctorInternal(Functor& f)
100 auto& SMPToolsAPI = vtkSMPToolsAPI::GetInstance();
101 SMPToolsAPI.For(first, last, grain, *
this);
103 vtkSMPTools_FunctorInternal<Functor, false>& operator=(
104 const vtkSMPTools_FunctorInternal<Functor, false>&);
105 vtkSMPTools_FunctorInternal<Functor, false>(
const vtkSMPTools_FunctorInternal<Functor, false>&);
108template <
typename Functor>
109struct vtkSMPTools_FunctorInternal<Functor, true>
112 vtkSMPThreadLocal<unsigned char> Initialized;
113 vtkSMPTools_FunctorInternal(Functor& f)
120 unsigned char& inited = this->Initialized.
Local();
123 this->F.Initialize();
126 this->F(first, last);
130 auto& SMPToolsAPI = vtkSMPToolsAPI::GetInstance();
131 SMPToolsAPI.For(first, last, grain, *
this);
134 vtkSMPTools_FunctorInternal<Functor, true>& operator=(
135 const vtkSMPTools_FunctorInternal<Functor, true>&);
136 vtkSMPTools_FunctorInternal<Functor, true>(
const vtkSMPTools_FunctorInternal<Functor, true>&);
139template <
typename Functor>
140class vtkSMPTools_Lookup_For
142 static bool const init = vtkSMPTools_Has_Initialize<Functor>::value;
145 typedef vtkSMPTools_FunctorInternal<Functor, init>
type;
148template <
typename Functor>
149class vtkSMPTools_Lookup_For<Functor const>
151 static bool const init = vtkSMPTools_Has_Initialize_const<Functor>::value;
154 typedef vtkSMPTools_FunctorInternal<Functor const, init>
type;
157template <
typename Iterator,
typename Functor,
bool Init>
158struct vtkSMPTools_RangeFunctor;
160template <
typename Iterator,
typename Functor>
161struct vtkSMPTools_RangeFunctor<Iterator, Functor, false>
165 vtkSMPTools_RangeFunctor(Iterator& begin, Functor& f)
172 Iterator itFirst(Begin);
173 std::advance(itFirst, first);
174 Iterator itLast(itFirst);
175 std::advance(itLast, last - first);
176 this->F(itFirst, itLast);
180template <
typename Iterator,
typename Functor>
181struct vtkSMPTools_RangeFunctor<Iterator, Functor, true>
185 vtkSMPTools_RangeFunctor(Iterator& begin, Functor& f)
190 void Initialize() { this->F.Initialize(); }
193 Iterator itFirst(Begin);
194 std::advance(itFirst, first);
195 Iterator itLast(itFirst);
196 std::advance(itLast, last - first);
197 this->F(itFirst, itLast);
199 void Reduce() { this->F.Reduce(); }
202template <
typename Iterator,
typename Functor>
203class vtkSMPTools_Lookup_RangeFor
205 static bool const init = vtkSMPTools_Has_Initialize<Functor>::value;
208 typedef vtkSMPTools_RangeFunctor<Iterator, Functor, init>
type;
211template <
typename Iterator,
typename Functor>
212class vtkSMPTools_Lookup_RangeFor<Iterator, Functor const>
214 static bool const init = vtkSMPTools_Has_Initialize_const<Functor>::value;
217 typedef vtkSMPTools_RangeFunctor<Iterator, Functor const, init>
type;
221using resolvedNotInt =
typename std::enable_if<!std::is_integral<T>::value,
void>::type;
240 template <
typename Functor>
243 typename vtk::detail::smp::vtkSMPTools_Lookup_For<Functor>::type fi(f);
244 fi.For(first, last, grain);
247 template <
typename Functor>
250 typename vtk::detail::smp::vtkSMPTools_Lookup_For<Functor const>::type fi(f);
251 fi.For(first, last, grain);
265 template <
typename Functor>
271 template <
typename Functor>
314 template <
typename Iter,
typename Functor>
315 static vtk::detail::smp::resolvedNotInt<Iter>
For(
316 Iter begin, Iter end,
vtkIdType grain, Functor& f)
318 vtkIdType size = std::distance(begin, end);
319 typename vtk::detail::smp::vtkSMPTools_Lookup_RangeFor<Iter, Functor>::type fi(begin, f);
323 template <
typename Iter,
typename Functor>
324 static vtk::detail::smp::resolvedNotInt<Iter>
For(
325 Iter begin, Iter end,
vtkIdType grain, Functor
const& f)
327 vtkIdType size = std::distance(begin, end);
328 typename vtk::detail::smp::vtkSMPTools_Lookup_RangeFor<Iter, Functor const>::type fi(begin, f);
367 template <
typename Iter,
typename Functor>
368 static vtk::detail::smp::resolvedNotInt<Iter>
For(Iter begin, Iter end, Functor& f)
373 template <
typename Iter,
typename Functor>
374 static vtk::detail::smp::resolvedNotInt<Iter>
For(Iter begin, Iter end, Functor
const& f)
472 Config(
int maxNumberOfThreads, std::string backend,
bool nestedParallelism)
478#ifndef DOXYGEN_SHOULD_SKIP_THIS
480 : MaxNumberOfThreads(API.GetInternalDesiredNumberOfThread())
499 template <
typename T>
521 template <
typename InputIt,
typename OutputIt,
typename Functor>
522 static void Transform(InputIt inBegin, InputIt inEnd, OutputIt outBegin, Functor transform)
525 SMPToolsAPI.Transform(inBegin, inEnd, outBegin, transform);
544 template <
typename InputIt1,
typename InputIt2,
typename OutputIt,
typename Functor>
546 InputIt1 inBegin1, InputIt1 inEnd, InputIt2 inBegin2, OutputIt outBegin, Functor transform)
549 SMPToolsAPI.Transform(inBegin1, inEnd, inBegin2, outBegin, transform);
566 template <
typename Iterator,
typename T>
567 static void Fill(Iterator begin, Iterator end,
const T& value)
570 SMPToolsAPI.Fill(begin, end, value);
578 template <
typename RandomAccessIterator>
579 static void Sort(RandomAccessIterator begin, RandomAccessIterator end)
582 SMPToolsAPI.Sort(begin, end);
591 template <
typename RandomAccessIterator,
typename Compare>
592 static void Sort(RandomAccessIterator begin, RandomAccessIterator end, Compare comp)
595 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.