VTK  9.3.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>
46 class VTKCOMMONCORE_EXPORT vtkSMPToolsImpl
47 {
48 public:
49  //--------------------------------------------------------------------------------
50  void Initialize(int numThreads = 0);
51 
52  //--------------------------------------------------------------------------------
53  int GetEstimatedNumberOfThreads();
54 
55  //--------------------------------------------------------------------------------
56  void SetNestedParallelism(bool isNested) { this->NestedActivated = isNested; }
57 
58  //--------------------------------------------------------------------------------
59  bool GetNestedParallelism() { return this->NestedActivated; }
60 
61  //--------------------------------------------------------------------------------
62  bool IsParallelScope() { return this->IsParallel; }
63 
64  //--------------------------------------------------------------------------------
65  bool GetSingleThread();
66 
67  //--------------------------------------------------------------------------------
68  template <typename FunctorInternal>
69  void For(vtkIdType first, vtkIdType last, vtkIdType grain, FunctorInternal& fi);
70 
71  //--------------------------------------------------------------------------------
72  template <typename InputIt, typename OutputIt, typename Functor>
73  void Transform(InputIt inBegin, InputIt inEnd, OutputIt outBegin, Functor transform);
74 
75  //--------------------------------------------------------------------------------
76  template <typename InputIt1, typename InputIt2, typename OutputIt, typename Functor>
77  void Transform(
78  InputIt1 inBegin1, InputIt1 inEnd, InputIt2 inBegin2, OutputIt outBegin, Functor transform);
79 
80  //--------------------------------------------------------------------------------
81  template <typename Iterator, typename T>
82  void Fill(Iterator begin, Iterator end, const T& value);
83 
84  //--------------------------------------------------------------------------------
85  template <typename RandomAccessIterator>
86  void Sort(RandomAccessIterator begin, RandomAccessIterator end);
87 
88  //--------------------------------------------------------------------------------
89  template <typename RandomAccessIterator, typename Compare>
90  void Sort(RandomAccessIterator begin, RandomAccessIterator end, Compare comp);
91 
92  //--------------------------------------------------------------------------------
94  : NestedActivated(true)
95  , IsParallel(false)
96  {
97  }
98 
99  //--------------------------------------------------------------------------------
101  : NestedActivated(other.NestedActivated)
102  , IsParallel(other.IsParallel.load())
103  {
104  }
105 
106  //--------------------------------------------------------------------------------
107  void operator=(const vtkSMPToolsImpl& other)
108  {
109  this->NestedActivated = other.NestedActivated;
110  this->IsParallel = other.IsParallel.load();
111  }
112 
113 private:
114  bool NestedActivated = false;
115  std::atomic<bool> IsParallel{ false };
116 };
117 
119 
120 VTK_ABI_NAMESPACE_END
121 } // namespace smp
122 } // namespace detail
123 } // namespace vtk
124 
125 #endif
126 /* VTK-HeaderTest-Exclude: vtkSMPToolsImpl.h */
#define VTK_SMP_BACKEND_TBB
void(*)(void *, vtkIdType, vtkIdType, vtkIdType) ExecuteFunctorPtrType
void Sort(RandomIt bitr, RandomIt eitr, BackToFront< T > &me)
void SetNestedParallelism(bool isNested)
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
int vtkIdType
Definition: vtkType.h:315
#define VTK_SMP_BACKEND_OPENMP
#define VTK_SMP_BACKEND_SEQUENTIAL
vtkSMPToolsImpl(const vtkSMPToolsImpl &other)
#define VTK_SMP_BACKEND_STDTHREAD
void operator=(const vtkSMPToolsImpl &other)