VTK  9.4.20241218
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
20namespace vtk
21{
22namespace detail
23{
24namespace smp
25{
26VTK_ABI_NAMESPACE_BEGIN
27enum class BackendType
28{
33};
34
35#if VTK_SMP_DEFAULT_IMPLEMENTATION_SEQUENTIAL
36const BackendType DefaultBackend = BackendType::Sequential;
37#elif VTK_SMP_DEFAULT_IMPLEMENTATION_STDTHREAD
38const BackendType DefaultBackend = BackendType::STDThread;
39#elif VTK_SMP_DEFAULT_IMPLEMENTATION_TBB
40const BackendType DefaultBackend = BackendType::TBB;
41#elif VTK_SMP_DEFAULT_IMPLEMENTATION_OPENMP
42const BackendType DefaultBackend = BackendType::OpenMP;
43#endif
44
45template <BackendType Backend>
47{
48public:
49 //--------------------------------------------------------------------------------
50 void Initialize(int numThreads = 0);
51
52 //--------------------------------------------------------------------------------
54
55 //--------------------------------------------------------------------------------
57
58 //--------------------------------------------------------------------------------
59 void SetNestedParallelism(bool isNested);
60
61 //--------------------------------------------------------------------------------
63
64 //--------------------------------------------------------------------------------
65 bool IsParallelScope();
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>
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
104private:
105 bool NestedActivated = false;
106 std::atomic<bool> IsParallel{ false };
107};
108
109template <BackendType Backend>
111{
112 this->NestedActivated = isNested;
113}
114
115template <BackendType Backend>
117{
118 return this->NestedActivated;
119}
120
121template <BackendType Backend>
123{
124 return this->IsParallel;
125}
126
127template <BackendType Backend>
129 : NestedActivated(true)
130 , IsParallel(false)
131{
132}
133
134template <BackendType Backend>
136 : NestedActivated(other.NestedActivated)
137 , IsParallel(other.IsParallel.load())
138{
139}
140
141template <BackendType Backend>
143{
144 this->NestedActivated = other.NestedActivated;
145 this->IsParallel = other.IsParallel.load();
146}
147
149
150VTK_ABI_NAMESPACE_END
151} // namespace smp
152} // namespace detail
153} // namespace vtk
154
155#endif
156/* 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)
void Initialize(int numThreads=0)
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
void load(Archiver &ar, std::string &str, const unsigned int vtkNotUsed(version))