VTK  9.2.6
vtkSMPToolsImpl.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkSMPToolsImpl.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
15
16#ifndef vtkSMPToolsImpl_h
17#define vtkSMPToolsImpl_h
18
19#include "vtkCommonCoreModule.h" // For export macro
20#include "vtkObject.h"
21#include "vtkSMP.h"
22
23#include <atomic>
24
25#define VTK_SMP_MAX_BACKENDS_NB 4
26
27#define VTK_SMP_BACKEND_SEQUENTIAL 0
28#define VTK_SMP_BACKEND_STDTHREAD 1
29#define VTK_SMP_BACKEND_TBB 2
30#define VTK_SMP_BACKEND_OPENMP 3
31
32namespace vtk
33{
34namespace detail
35{
36namespace smp
37{
38
39enum class BackendType
40{
45};
46
47#if VTK_SMP_DEFAULT_IMPLEMENTATION_SEQUENTIAL
48const BackendType DefaultBackend = BackendType::Sequential;
49#elif VTK_SMP_DEFAULT_IMPLEMENTATION_STDTHREAD
50const BackendType DefaultBackend = BackendType::STDThread;
51#elif VTK_SMP_DEFAULT_IMPLEMENTATION_TBB
52const BackendType DefaultBackend = BackendType::TBB;
53#elif VTK_SMP_DEFAULT_IMPLEMENTATION_OPENMP
54const BackendType DefaultBackend = BackendType::OpenMP;
55#endif
56
57template <BackendType Backend>
58class VTKCOMMONCORE_EXPORT vtkSMPToolsImpl
59{
60public:
61 //--------------------------------------------------------------------------------
62 void Initialize(int numThreads = 0);
63
64 //--------------------------------------------------------------------------------
66
67 //--------------------------------------------------------------------------------
68 void SetNestedParallelism(bool isNested) { this->NestedActivated = isNested; }
69
70 //--------------------------------------------------------------------------------
71 bool GetNestedParallelism() { return this->NestedActivated; }
72
73 //--------------------------------------------------------------------------------
74 bool IsParallelScope() { return this->IsParallel; }
75
76 //--------------------------------------------------------------------------------
77 template <typename FunctorInternal>
78 void For(vtkIdType first, vtkIdType last, vtkIdType grain, FunctorInternal& fi);
79
80 //--------------------------------------------------------------------------------
81 template <typename InputIt, typename OutputIt, typename Functor>
82 void Transform(InputIt inBegin, InputIt inEnd, OutputIt outBegin, Functor transform);
83
84 //--------------------------------------------------------------------------------
85 template <typename InputIt1, typename InputIt2, typename OutputIt, typename Functor>
87 InputIt1 inBegin1, InputIt1 inEnd, InputIt2 inBegin2, OutputIt outBegin, Functor transform);
88
89 //--------------------------------------------------------------------------------
90 template <typename Iterator, typename T>
91 void Fill(Iterator begin, Iterator end, const T& value);
92
93 //--------------------------------------------------------------------------------
94 template <typename RandomAccessIterator>
95 void Sort(RandomAccessIterator begin, RandomAccessIterator end);
96
97 //--------------------------------------------------------------------------------
98 template <typename RandomAccessIterator, typename Compare>
99 void Sort(RandomAccessIterator begin, RandomAccessIterator end, Compare comp);
100
101 //--------------------------------------------------------------------------------
103 : NestedActivated(true)
104 , IsParallel(false)
105 {
106 }
107
108 //--------------------------------------------------------------------------------
110 : NestedActivated(other.NestedActivated)
111 , IsParallel(other.IsParallel.load())
112 {
113 }
114
115 //--------------------------------------------------------------------------------
116 void operator=(const vtkSMPToolsImpl& other)
117 {
118 this->NestedActivated = other.NestedActivated;
119 this->IsParallel = other.IsParallel.load();
120 }
121
122private:
123 bool NestedActivated = true;
124 std::atomic<bool> IsParallel{ false };
125};
126
128
129} // namespace smp
130} // namespace detail
131} // namespace vtk
132
133#endif
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:332
void load(Archiver &ar, std::string &str, const unsigned int vtkNotUsed(version))