33#include "vtkCommonCoreModule.h"
43#ifndef DOXYGEN_SHOULD_SKIP_THIS
52class vtkSMPTools_Has_Initialize
54 typedef char (&no_type)[1];
55 typedef char (&yes_type)[2];
56 template <
typename U,
void (U::*)()>
61 static yes_type check(V<U, &U::Initialize>*);
63 static no_type check(...);
66 static bool const value =
sizeof(check<T>(
nullptr)) ==
sizeof(yes_type);
70class vtkSMPTools_Has_Initialize_const
72 typedef char (&no_type)[1];
73 typedef char (&yes_type)[2];
74 template <
typename U,
void (U::*)() const>
79 static yes_type check(V<U, &U::Initialize>*);
81 static no_type check(...);
84 static bool const value =
sizeof(check<T>(0)) ==
sizeof(yes_type);
87template <
typename Functor,
bool Init>
88struct vtkSMPTools_FunctorInternal;
90template <
typename Functor>
91struct vtkSMPTools_FunctorInternal<Functor, false>
94 vtkSMPTools_FunctorInternal(Functor& f)
101 auto& SMPToolsAPI = vtkSMPToolsAPI::GetInstance();
102 SMPToolsAPI.For(first, last, grain, *
this);
104 vtkSMPTools_FunctorInternal<Functor, false>& operator=(
105 const vtkSMPTools_FunctorInternal<Functor, false>&);
106 vtkSMPTools_FunctorInternal<Functor, false>(
const vtkSMPTools_FunctorInternal<Functor, false>&);
109template <
typename Functor>
110struct vtkSMPTools_FunctorInternal<Functor, true>
114 vtkSMPTools_FunctorInternal(Functor& f)
121 unsigned char& inited = this->Initialized.
Local();
124 this->F.Initialize();
127 this->F(first, last);
131 auto& SMPToolsAPI = vtkSMPToolsAPI::GetInstance();
132 SMPToolsAPI.For(first, last, grain, *
this);
135 vtkSMPTools_FunctorInternal<Functor, true>& operator=(
136 const vtkSMPTools_FunctorInternal<Functor, true>&);
137 vtkSMPTools_FunctorInternal<Functor, true>(
const vtkSMPTools_FunctorInternal<Functor, true>&);
140template <
typename Functor>
141class vtkSMPTools_Lookup_For
143 static bool const init = vtkSMPTools_Has_Initialize<Functor>::value;
146 typedef vtkSMPTools_FunctorInternal<Functor, init>
type;
149template <
typename Functor>
150class vtkSMPTools_Lookup_For<Functor const>
152 static bool const init = vtkSMPTools_Has_Initialize_const<Functor>::value;
155 typedef vtkSMPTools_FunctorInternal<Functor const, init>
type;
158template <
typename Iterator,
typename Functor,
bool Init>
159struct vtkSMPTools_RangeFunctor;
161template <
typename Iterator,
typename Functor>
162struct vtkSMPTools_RangeFunctor<Iterator, Functor, false>
166 vtkSMPTools_RangeFunctor(Iterator& begin, Functor& f)
173 Iterator itFirst(Begin);
174 std::advance(itFirst, first);
175 Iterator itLast(itFirst);
176 std::advance(itLast, last - first);
177 this->F(itFirst, itLast);
181template <
typename Iterator,
typename Functor>
182struct vtkSMPTools_RangeFunctor<Iterator, Functor, true>
186 vtkSMPTools_RangeFunctor(Iterator& begin, Functor& f)
191 void Initialize() { this->F.Initialize(); }
194 Iterator itFirst(Begin);
195 std::advance(itFirst, first);
196 Iterator itLast(itFirst);
197 std::advance(itLast, last - first);
198 this->F(itFirst, itLast);
200 void Reduce() { this->F.Reduce(); }
203template <
typename Iterator,
typename Functor>
204class vtkSMPTools_Lookup_RangeFor
206 static bool const init = vtkSMPTools_Has_Initialize<Functor>::value;
209 typedef vtkSMPTools_RangeFunctor<Iterator, Functor, init>
type;
212template <
typename Iterator,
typename Functor>
213class vtkSMPTools_Lookup_RangeFor<Iterator, Functor const>
215 static bool const init = vtkSMPTools_Has_Initialize_const<Functor>::value;
218 typedef vtkSMPTools_RangeFunctor<Iterator, Functor const, init>
type;
222using resolvedNotInt =
typename std::enable_if<!std::is_integral<T>::value,
void>::type;
242 template <
typename Functor>
245 typename vtk::detail::smp::vtkSMPTools_Lookup_For<Functor>::type fi(f);
246 fi.For(first, last, grain);
249 template <
typename Functor>
252 typename vtk::detail::smp::vtkSMPTools_Lookup_For<Functor const>::type fi(f);
253 fi.For(first, last, grain);
267 template <
typename Functor>
273 template <
typename Functor>
316 template <
typename Iter,
typename Functor>
317 static vtk::detail::smp::resolvedNotInt<Iter>
For(
318 Iter begin, Iter end,
vtkIdType grain, Functor& f)
320 vtkIdType size = std::distance(begin, end);
321 typename vtk::detail::smp::vtkSMPTools_Lookup_RangeFor<Iter, Functor>::type fi(begin, f);
325 template <
typename Iter,
typename Functor>
326 static vtk::detail::smp::resolvedNotInt<Iter>
For(
327 Iter begin, Iter end,
vtkIdType grain, Functor
const& f)
329 vtkIdType size = std::distance(begin, end);
330 typename vtk::detail::smp::vtkSMPTools_Lookup_RangeFor<Iter, Functor const>::type fi(begin, f);
369 template <
typename Iter,
typename Functor>
370 static vtk::detail::smp::resolvedNotInt<Iter>
For(Iter begin, Iter end, Functor& f)
375 template <
typename Iter,
typename Functor>
376 static vtk::detail::smp::resolvedNotInt<Iter>
For(Iter begin, Iter end, Functor
const& f)
457 int MaxNumberOfThreads = 0;
459 bool NestedParallelism =
true;
463 : MaxNumberOfThreads(maxNumberOfThreads)
471 : NestedParallelism(nestedParallelism)
474 Config(
int maxNumberOfThreads, std::string backend,
bool nestedParallelism)
475 : MaxNumberOfThreads(maxNumberOfThreads)
477 , NestedParallelism(nestedParallelism)
480#ifndef DOXYGEN_SHOULD_SKIP_THIS
482 : MaxNumberOfThreads(API.GetInternalDesiredNumberOfThread())
483 , Backend(API.GetBackend())
484 , NestedParallelism(API.GetNestedParallelism())
501 template <
typename T>
523 template <
typename InputIt,
typename OutputIt,
typename Functor>
524 static void Transform(InputIt inBegin, InputIt inEnd, OutputIt outBegin, Functor transform)
527 SMPToolsAPI.Transform(inBegin, inEnd, outBegin, transform);
546 template <
typename InputIt1,
typename InputIt2,
typename OutputIt,
typename Functor>
548 InputIt1 inBegin1, InputIt1 inEnd, InputIt2 inBegin2, OutputIt outBegin, Functor transform)
551 SMPToolsAPI.Transform(inBegin1, inEnd, inBegin2, outBegin, transform);
568 template <
typename Iterator,
typename T>
569 static void Fill(Iterator begin, Iterator end,
const T& value)
572 SMPToolsAPI.Fill(begin, end, value);
580 template <
typename RandomAccessIterator>
581 static void Sort(RandomAccessIterator begin, RandomAccessIterator end)
584 SMPToolsAPI.Sort(begin, end);
593 template <
typename RandomAccessIterator,
typename Compare>
594 static void Sort(RandomAccessIterator begin, RandomAccessIterator end, Compare comp)
597 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.