VTK  9.7.1
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>
47 {
48 public:
49  //--------------------------------------------------------------------------------
50  void Initialize(int numThreads = 0);
51 
52  //--------------------------------------------------------------------------------
54 
55  //--------------------------------------------------------------------------------
57 
58  //--------------------------------------------------------------------------------
59  void SetNestedParallelism(bool isNested);
60 
61  //--------------------------------------------------------------------------------
62  bool GetNestedParallelism();
63 
64  //--------------------------------------------------------------------------------
65  bool IsParallelScope();
66 
67  //--------------------------------------------------------------------------------
68  bool GetSingleThread();
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 
98  //--------------------------------------------------------------------------------
99  vtkSMPToolsImpl(const vtkSMPToolsImpl& other);
100 
101  //--------------------------------------------------------------------------------
102  void operator=(const vtkSMPToolsImpl& other);
103 
104 private:
105  bool NestedActivated = false;
106  std::atomic<bool> IsParallel{ false };
107 };
108 
109 template <BackendType Backend>
111 {
112  this->NestedActivated = isNested;
113 }
114 
115 template <BackendType Backend>
117 {
118  return this->NestedActivated;
119 }
120 
121 template <BackendType Backend>
123 {
124  return this->IsParallel;
125 }
126 
127 template <BackendType Backend>
129  : NestedActivated(true)
130  , IsParallel(false)
131 {
132 }
133 
134 template <BackendType Backend>
136  : NestedActivated(other.NestedActivated)
137  , IsParallel(other.IsParallel.load())
138 {
139 }
140 
141 template <BackendType Backend>
143 {
144  this->NestedActivated = other.NestedActivated;
145  this->IsParallel = other.IsParallel.load();
146 }
147 
149 
150 VTK_ABI_NAMESPACE_END
151 } // namespace smp
152 } // namespace detail
153 } // namespace vtk
154 
155 #endif
156 /* VTK-HeaderTest-Exclude: vtkSMPToolsImpl.h */
static int GetEstimatedDefaultNumberOfThreads()
#define VTK_SMP_BACKEND_TBB
void Initialize(int numThreads=0)
void For(vtkIdType first, vtkIdType last, vtkIdType grain, FunctorInternal &fi)
void(*)(void *, vtkIdType, vtkIdType, vtkIdType) ExecuteFunctorPtrType
void SetNestedParallelism(bool isNested)
void Fill(Iterator begin, Iterator end, const T &value)
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
int vtkIdType
Definition: vtkType.h:363
#define VTK_SMP_BACKEND_OPENMP
#define VTK_SMP_BACKEND_SEQUENTIAL
#define VTK_SMP_BACKEND_STDTHREAD
void Sort(RandomAccessIterator begin, RandomAccessIterator end)
void operator=(const vtkSMPToolsImpl &other)
void Transform(InputIt inBegin, InputIt inEnd, OutputIt outBegin, Functor transform)