27#include "vtkCommonCoreModule.h"
36#ifndef DOXYGEN_SHOULD_SKIP_THIS
43VTK_ABI_NAMESPACE_BEGIN
45class vtkSMPTools_Has_Initialize
47 typedef char (&no_type)[1];
48 typedef char (&yes_type)[2];
49 template <
typename U,
void (U::*)()>
54 static yes_type check(V<U, &U::Initialize>*);
56 static no_type check(...);
59 static bool const value =
sizeof(check<T>(
nullptr)) ==
sizeof(yes_type);
63class vtkSMPTools_Has_Initialize_const
65 typedef char (&no_type)[1];
66 typedef char (&yes_type)[2];
67 template <
typename U,
void (U::*)() const>
72 static yes_type check(V<U, &U::Initialize>*);
74 static no_type check(...);
77 static bool const value =
sizeof(check<T>(0)) ==
sizeof(yes_type);
80template <
typename Functor,
bool Init>
81struct vtkSMPTools_FunctorInternal;
83template <
typename Functor>
84struct vtkSMPTools_FunctorInternal<Functor, false>
87 vtkSMPTools_FunctorInternal(Functor& f)
94 auto& SMPToolsAPI = vtkSMPToolsAPI::GetInstance();
95 SMPToolsAPI.For(first, last, grain, *
this);
97 vtkSMPTools_FunctorInternal<Functor, false>& operator=(
98 const vtkSMPTools_FunctorInternal<Functor, false>&);
99 vtkSMPTools_FunctorInternal(
const vtkSMPTools_FunctorInternal<Functor, false>&);
102template <
typename Functor>
103struct vtkSMPTools_FunctorInternal<Functor, true>
107 vtkSMPTools_FunctorInternal(Functor& f)
114 unsigned char& inited = this->Initialized.
Local();
117 this->F.Initialize();
120 this->F(first, last);
124 auto& SMPToolsAPI = vtkSMPToolsAPI::GetInstance();
125 SMPToolsAPI.For(first, last, grain, *
this);
128 vtkSMPTools_FunctorInternal<Functor, true>& operator=(
129 const vtkSMPTools_FunctorInternal<Functor, true>&);
130 vtkSMPTools_FunctorInternal(
const vtkSMPTools_FunctorInternal<Functor, true>&);
133template <
typename Functor>
134class vtkSMPTools_Lookup_For
136 static bool const init = vtkSMPTools_Has_Initialize<Functor>::value;
139 typedef vtkSMPTools_FunctorInternal<Functor, init>
type;
142template <
typename Functor>
143class vtkSMPTools_Lookup_For<Functor const>
145 static bool const init = vtkSMPTools_Has_Initialize_const<Functor>::value;
148 typedef vtkSMPTools_FunctorInternal<Functor const, init>
type;
151template <
typename Iterator,
typename Functor,
bool Init>
152struct vtkSMPTools_RangeFunctor;
154template <
typename Iterator,
typename Functor>
155struct vtkSMPTools_RangeFunctor<Iterator, Functor, false>
159 vtkSMPTools_RangeFunctor(Iterator& begin, Functor& f)
166 Iterator itFirst(Begin);
167 std::advance(itFirst, first);
168 Iterator itLast(itFirst);
169 std::advance(itLast, last - first);
170 this->F(itFirst, itLast);
174template <
typename Iterator,
typename Functor>
175struct vtkSMPTools_RangeFunctor<Iterator, Functor, true>
179 vtkSMPTools_RangeFunctor(Iterator& begin, Functor& f)
184 void Initialize() { this->F.Initialize(); }
187 Iterator itFirst(Begin);
188 std::advance(itFirst, first);
189 Iterator itLast(itFirst);
190 std::advance(itLast, last - first);
191 this->F(itFirst, itLast);
193 void Reduce() { this->F.Reduce(); }
196template <
typename Iterator,
typename Functor>
197class vtkSMPTools_Lookup_RangeFor
199 static bool const init = vtkSMPTools_Has_Initialize<Functor>::value;
202 typedef vtkSMPTools_RangeFunctor<Iterator, Functor, init>
type;
205template <
typename Iterator,
typename Functor>
206class vtkSMPTools_Lookup_RangeFor<Iterator, Functor const>
208 static bool const init = vtkSMPTools_Has_Initialize_const<Functor>::value;
211 typedef vtkSMPTools_RangeFunctor<Iterator, Functor const, init>
type;
215using resolvedNotInt =
typename std::enable_if<!std::is_integral<T>::value,
void>::type;
222VTK_ABI_NAMESPACE_BEGIN
236 template <
typename Functor>
239 typename vtk::detail::smp::vtkSMPTools_Lookup_For<Functor>::type fi(f);
240 fi.For(first, last, grain);
243 template <
typename Functor>
246 typename vtk::detail::smp::vtkSMPTools_Lookup_For<Functor const>::type fi(f);
247 fi.For(first, last, grain);
261 template <
typename Functor>
267 template <
typename Functor>
310 template <
typename Iter,
typename Functor>
311 static vtk::detail::smp::resolvedNotInt<Iter>
For(
312 Iter begin, Iter end,
vtkIdType grain, Functor& f)
314 vtkIdType size = std::distance(begin, end);
315 typename vtk::detail::smp::vtkSMPTools_Lookup_RangeFor<Iter, Functor>::type fi(begin, f);
319 template <
typename Iter,
typename Functor>
320 static vtk::detail::smp::resolvedNotInt<Iter>
For(
321 Iter begin, Iter end,
vtkIdType grain, Functor
const& f)
323 vtkIdType size = std::distance(begin, end);
324 typename vtk::detail::smp::vtkSMPTools_Lookup_RangeFor<Iter, Functor const>::type fi(begin, f);
363 template <
typename Iter,
typename Functor>
364 static vtk::detail::smp::resolvedNotInt<Iter>
For(Iter begin, Iter end, Functor& f)
369 template <
typename Iter,
typename Functor>
370 static vtk::detail::smp::resolvedNotInt<Iter>
For(Iter begin, Iter end, Functor
const& f)
466 int MaxNumberOfThreads = 0;
468 bool NestedParallelism =
false;
472 : MaxNumberOfThreads(maxNumberOfThreads)
480 : NestedParallelism(nestedParallelism)
483 Config(
int maxNumberOfThreads, std::string backend,
bool nestedParallelism)
484 : MaxNumberOfThreads(maxNumberOfThreads)
486 , NestedParallelism(nestedParallelism)
489#ifndef DOXYGEN_SHOULD_SKIP_THIS
491 : MaxNumberOfThreads(API.GetInternalDesiredNumberOfThread())
492 , Backend(API.GetBackend())
493 , NestedParallelism(API.GetNestedParallelism())
534 template <
typename T>
556 template <
typename InputIt,
typename OutputIt,
typename Functor>
557 static void Transform(InputIt inBegin, InputIt inEnd, OutputIt outBegin, Functor transform)
560 SMPToolsAPI.Transform(inBegin, inEnd, outBegin, transform);
579 template <
typename InputIt1,
typename InputIt2,
typename OutputIt,
typename Functor>
581 InputIt1 inBegin1, InputIt1 inEnd, InputIt2 inBegin2, OutputIt outBegin, Functor transform)
584 SMPToolsAPI.Transform(inBegin1, inEnd, inBegin2, outBegin, transform);
601 template <
typename Iterator,
typename T>
602 static void Fill(Iterator begin, Iterator end,
const T& value)
605 SMPToolsAPI.Fill(begin, end, value);
613 template <
typename RandomAccessIterator>
614 static void Sort(RandomAccessIterator begin, RandomAccessIterator end)
617 SMPToolsAPI.Sort(begin, end);
626 template <
typename RandomAccessIterator,
typename Compare>
627 static void Sort(RandomAccessIterator begin, RandomAccessIterator end, Compare comp)
630 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.