VTK
vtkSMPTools.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkSMPTools.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 =========================================================================*/
28 #ifndef __vtkSMPTools_h__
29 #define __vtkSMPTools_h__
30 
31 #include "vtkCommonCoreModule.h" // For export macro
32 #include "vtkObject.h"
33 
34 #include "vtkSMPThreadLocal.h" // For Initialized
35 
36 class vtkSMPTools;
37 
38 #include "vtkSMPToolsInternal.h"
39 
40 #ifndef DOXYGEN_SHOULD_SKIP_THIS
41 #ifndef __WRAP__
42 namespace vtk
43 {
44 namespace detail
45 {
46 namespace smp
47 {
48 template <typename T>
50 {
51  typedef char (&no_type)[1];
52  typedef char (&yes_type)[2];
53  template <typename U, void (U::*)()> struct V {};
54  template <typename U> static yes_type check(V<U, &U::Initialize>*);
55  template <typename U> static no_type check(...);
56 public:
57  static bool const value = sizeof(check<T>(0)) == sizeof(yes_type);
58 };
59 
60 template <typename T>
62 {
63  typedef char (&no_type)[1];
64  typedef char (&yes_type)[2];
65  template <typename U, void (U::*)() const> struct V {};
66  template <typename U> static yes_type check(V<U, &U::Initialize>*);
67  template <typename U> static no_type check(...);
68 public:
69  static bool const value = sizeof(check<T>(0)) == sizeof(yes_type);
70 };
71 
72 template <typename Functor, bool Init>
74 
75 template <typename Functor>
76 struct vtkSMPTools_FunctorInternal<Functor, false>
77 {
78  Functor& F;
79  vtkSMPTools_FunctorInternal(Functor& f): F(f) {}
81  {
82  this->F(first, last);
83  }
84  void For(vtkIdType first, vtkIdType last, vtkIdType grain)
85  {
86  vtk::detail::smp::vtkSMPTools_Impl_For(first, last, grain, *this);
87  }
92 };
93 
94 template <typename Functor>
95 struct vtkSMPTools_FunctorInternal<Functor, true>
96 {
97  Functor& F;
99  vtkSMPTools_FunctorInternal(Functor& f): F(f), Initialized(0) {}
101  {
102  unsigned char& inited = this->Initialized.Local();
103  if (!inited)
104  {
105  this->F.Initialize();
106  inited = 1;
107  }
108  this->F(first, last);
109  }
110  void For(vtkIdType first, vtkIdType last, vtkIdType grain)
111  {
112  vtk::detail::smp::vtkSMPTools_Impl_For(first, last, grain, *this);
113  this->F.Reduce();
114  }
119 };
120 
121 template <typename Functor>
123 {
124  static bool const init = vtkSMPTools_Has_Initialize<Functor>::value;
125 public:
127 };
128 
129 template <typename Functor>
130 class vtkSMPTools_Lookup_For<Functor const>
131 {
132  static bool const init = vtkSMPTools_Has_Initialize_const<Functor>::value;
133 public:
135 };
136 } // namespace smp
137 } // namespace detail
138 } // namespace vtk
139 #endif // __WRAP__
140 #endif // DOXYGEN_SHOULD_SKIP_THIS
141 
143 {
144 public:
145 
147 
153  template <typename Functor>
154  static void For(vtkIdType first, vtkIdType last, vtkIdType grain, Functor& f)
155  {
157  fi.For(first, last, grain);
158  }
160 
162 
168  template <typename Functor>
169  static void For(vtkIdType first, vtkIdType last, vtkIdType grain, Functor const& f)
170  {
172  fi.For(first, last, grain);
173  }
175 
177 
183  template <typename Functor>
184  static void For(vtkIdType first, vtkIdType last, Functor& f)
185  {
186  vtkSMPTools::For(first, last, 0, f);
187  }
189 
191 
197  template <typename Functor>
198  static void For(vtkIdType first, vtkIdType last, Functor const& f)
199  {
200  vtkSMPTools::For(first, last, 0, f);
201  }
203 
205 
212  static void Initialize(int numThreads=0);
213 };
215 
216 #endif
217 // VTK-HeaderTest-Exclude: vtkSMPTools.h
GLclampf f
Definition: vtkgl.h:14181
const GLint * first
Definition: vtkgl.h:11686
vtkSMPTools_FunctorInternal< Functor const, init > type
Definition: vtkSMPTools.h:134
#define VTKCOMMONCORE_EXPORT
void For(vtkIdType first, vtkIdType last, vtkIdType grain)
Definition: vtkSMPTools.h:110
static void For(vtkIdType first, vtkIdType last, Functor const &f)
Definition: vtkSMPTools.h:198
int vtkIdType
Definition: vtkType.h:268
static void vtkSMPTools_Impl_For(vtkIdType first, vtkIdType last, vtkIdType grain, FunctorInternal &fi)
static void For(vtkIdType first, vtkIdType last, Functor &f)
Definition: vtkSMPTools.h:184
static void For(vtkIdType first, vtkIdType last, vtkIdType grain, Functor &f)
Definition: vtkSMPTools.h:154
A set of parallel (multi-threaded) utility functions.
Definition: vtkSMPTools.h:142
static void For(vtkIdType first, vtkIdType last, vtkIdType grain, Functor const &f)
Definition: vtkSMPTools.h:169
void For(vtkIdType first, vtkIdType last, vtkIdType grain)
Definition: vtkSMPTools.h:84
vtkSMPTools_FunctorInternal< Functor, init > type
Definition: vtkSMPTools.h:126