VTK  9.3.0
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>
46class VTKCOMMONCORE_EXPORT vtkSMPToolsImpl
47{
48public:
49 //--------------------------------------------------------------------------------
50 void Initialize(int numThreads = 0);
51
52 //--------------------------------------------------------------------------------
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 //--------------------------------------------------------------------------------
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>
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
113private:
114 bool NestedActivated = false;
115 std::atomic<bool> IsParallel{ false };
116};
117
119
120VTK_ABI_NAMESPACE_END
121} // namespace smp
122} // namespace detail
123} // namespace vtk
124
125#endif
126/* 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)
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))