VTK  9.3.20240328
vtkSMPToolsImpl.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 
4 #ifndef vtkSMPToolsImpl_h
5 #define vtkSMPToolsImpl_h
6 
7 #include "vtkCommonCoreModule.h" // For export macro
8 #include "vtkObject.h"
9 #include "vtkSMP.h"
10 
11 #include <atomic>
12 
13 #define VTK_SMP_MAX_BACKENDS_NB 4
14 
15 #define VTK_SMP_BACKEND_SEQUENTIAL 0
16 #define VTK_SMP_BACKEND_STDTHREAD 1
17 #define VTK_SMP_BACKEND_TBB 2
18 #define VTK_SMP_BACKEND_OPENMP 3
19 
20 namespace vtk
21 {
22 namespace detail
23 {
24 namespace smp
25 {
26 VTK_ABI_NAMESPACE_BEGIN
27 enum class BackendType
28 {
33 };
34 
35 #if VTK_SMP_DEFAULT_IMPLEMENTATION_SEQUENTIAL
36 const BackendType DefaultBackend = BackendType::Sequential;
37 #elif VTK_SMP_DEFAULT_IMPLEMENTATION_STDTHREAD
38 const BackendType DefaultBackend = BackendType::STDThread;
39 #elif VTK_SMP_DEFAULT_IMPLEMENTATION_TBB
40 const BackendType DefaultBackend = BackendType::TBB;
41 #elif VTK_SMP_DEFAULT_IMPLEMENTATION_OPENMP
42 const BackendType DefaultBackend = BackendType::OpenMP;
43 #endif
44 
45 template <BackendType Backend>
46 class VTKCOMMONCORE_EXPORT vtkSMPToolsImpl
47 {
48 public:
49  //--------------------------------------------------------------------------------
50  void Initialize(int numThreads = 0);
51 
52  //--------------------------------------------------------------------------------
54 
55  //--------------------------------------------------------------------------------
57 
58  //--------------------------------------------------------------------------------
59  void SetNestedParallelism(bool isNested) { this->NestedActivated = isNested; }
60 
61  //--------------------------------------------------------------------------------
62  bool GetNestedParallelism() { return this->NestedActivated; }
63 
64  //--------------------------------------------------------------------------------
65  bool IsParallelScope() { return this->IsParallel; }
66 
67  //--------------------------------------------------------------------------------
69 
70  //--------------------------------------------------------------------------------
71  template <typename FunctorInternal>
72  void For(vtkIdType first, vtkIdType last, vtkIdType grain, FunctorInternal& fi);
73 
74  //--------------------------------------------------------------------------------
75  template <typename InputIt, typename OutputIt, typename Functor>
76  void Transform(InputIt inBegin, InputIt inEnd, OutputIt outBegin, Functor transform);
77 
78  //--------------------------------------------------------------------------------
79  template <typename InputIt1, typename InputIt2, typename OutputIt, typename Functor>
80  void Transform(
81  InputIt1 inBegin1, InputIt1 inEnd, InputIt2 inBegin2, OutputIt outBegin, Functor transform);
82 
83  //--------------------------------------------------------------------------------
84  template <typename Iterator, typename T>
85  void Fill(Iterator begin, Iterator end, const T& value);
86 
87  //--------------------------------------------------------------------------------
88  template <typename RandomAccessIterator>
89  void Sort(RandomAccessIterator begin, RandomAccessIterator end);
90 
91  //--------------------------------------------------------------------------------
92  template <typename RandomAccessIterator, typename Compare>
93  void Sort(RandomAccessIterator begin, RandomAccessIterator end, Compare comp);
94 
95  //--------------------------------------------------------------------------------
97  : NestedActivated(true)
98  , IsParallel(false)
99  {
100  }
101 
102  //--------------------------------------------------------------------------------
104  : NestedActivated(other.NestedActivated)
105  , IsParallel(other.IsParallel.load())
106  {
107  }
108 
109  //--------------------------------------------------------------------------------
110  void operator=(const vtkSMPToolsImpl& other)
111  {
112  this->NestedActivated = other.NestedActivated;
113  this->IsParallel = other.IsParallel.load();
114  }
115 
116 private:
117  bool NestedActivated = false;
118  std::atomic<bool> IsParallel{ false };
119 };
120 
122 
123 VTK_ABI_NAMESPACE_END
124 } // namespace smp
125 } // namespace detail
126 } // namespace vtk
127 
128 #endif
129 /* VTK-HeaderTest-Exclude: vtkSMPToolsImpl.h */
void Sort(RandomAccessIterator begin, RandomAccessIterator end)
void For(vtkIdType first, vtkIdType last, vtkIdType grain, FunctorInternal &fi)
void Transform(InputIt inBegin, InputIt inEnd, OutputIt outBegin, Functor transform)
void SetNestedParallelism(bool isNested)
void Sort(RandomAccessIterator begin, RandomAccessIterator end, Compare comp)
void Fill(Iterator begin, Iterator end, const T &value)
void Transform(InputIt1 inBegin1, InputIt1 inEnd, InputIt2 inBegin2, OutputIt outBegin, Functor transform)
void operator=(const vtkSMPToolsImpl &other)
vtkSMPToolsImpl(const vtkSMPToolsImpl &other)
void Initialize(int numThreads=0)
@ load
Definition: vtkX3D.h:403
@ value
Definition: vtkX3D.h:220
void(*)(void *, vtkIdType, vtkIdType, vtkIdType) ExecuteFunctorPtrType
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
#define VTK_SMP_BACKEND_TBB
#define VTK_SMP_BACKEND_STDTHREAD
#define VTK_SMP_BACKEND_SEQUENTIAL
#define VTK_SMP_BACKEND_OPENMP
int vtkIdType
Definition: vtkType.h:315