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 =========================================================================*/
31 #ifndef vtkSMPTools_h__
32 #define vtkSMPTools_h__
33 
34 #include "vtkCommonCoreModule.h" // For export macro
35 #include "vtkObject.h"
36 
37 #include "vtkSMPThreadLocal.h" // For Initialized
38 
39 class vtkSMPTools;
40 
41 #include "vtkSMPToolsInternal.h"
42 
43 #ifndef DOXYGEN_SHOULD_SKIP_THIS
44 #ifndef __WRAP__
45 namespace vtk
46 {
47 namespace detail
48 {
49 namespace smp
50 {
51 template <typename T>
53 {
54  typedef char (&no_type)[1];
55  typedef char (&yes_type)[2];
56  template <typename U, void (U::*)()> struct V {};
57  template <typename U> static yes_type check(V<U, &U::Initialize>*);
58  template <typename U> static no_type check(...);
59 public:
60  static bool const value = sizeof(check<T>(0)) == sizeof(yes_type);
61 };
62 
63 template <typename T>
65 {
66  typedef char (&no_type)[1];
67  typedef char (&yes_type)[2];
68  template <typename U, void (U::*)() const> struct V {};
69  template <typename U> static yes_type check(V<U, &U::Initialize>*);
70  template <typename U> static no_type check(...);
71 public:
72  static bool const value = sizeof(check<T>(0)) == sizeof(yes_type);
73 };
74 
75 template <typename Functor, bool Init>
77 
78 template <typename Functor>
79 struct vtkSMPTools_FunctorInternal<Functor, false>
80 {
81  Functor& F;
82  vtkSMPTools_FunctorInternal(Functor& f): F(f) {}
84  {
85  this->F(first, last);
86  }
87  void For(vtkIdType first, vtkIdType last, vtkIdType grain)
88  {
89  vtk::detail::smp::vtkSMPTools_Impl_For(first, last, grain, *this);
90  }
95 };
96 
97 template <typename Functor>
98 struct vtkSMPTools_FunctorInternal<Functor, true>
99 {
100  Functor& F;
102  vtkSMPTools_FunctorInternal(Functor& f): F(f), Initialized(0) {}
104  {
105  unsigned char& inited = this->Initialized.Local();
106  if (!inited)
107  {
108  this->F.Initialize();
109  inited = 1;
110  }
111  this->F(first, last);
112  }
113  void For(vtkIdType first, vtkIdType last, vtkIdType grain)
114  {
115  vtk::detail::smp::vtkSMPTools_Impl_For(first, last, grain, *this);
116  this->F.Reduce();
117  }
122 };
123 
124 template <typename Functor>
126 {
127  static bool const init = vtkSMPTools_Has_Initialize<Functor>::value;
128 public:
130 };
131 
132 template <typename Functor>
133 class vtkSMPTools_Lookup_For<Functor const>
134 {
135  static bool const init = vtkSMPTools_Has_Initialize_const<Functor>::value;
136 public:
138 };
139 } // namespace smp
140 } // namespace detail
141 } // namespace vtk
142 #endif // __WRAP__
143 #endif // DOXYGEN_SHOULD_SKIP_THIS
144 
146 {
147 public:
148 
150 
156  template <typename Functor>
157  static void For(vtkIdType first, vtkIdType last, vtkIdType grain, Functor& f)
158  {
160  fi.For(first, last, grain);
161  }
163 
165 
171  template <typename Functor>
172  static void For(vtkIdType first, vtkIdType last, vtkIdType grain, Functor const& f)
173  {
175  fi.For(first, last, grain);
176  }
178 
180 
186  template <typename Functor>
187  static void For(vtkIdType first, vtkIdType last, Functor& f)
188  {
189  vtkSMPTools::For(first, last, 0, f);
190  }
192 
194 
200  template <typename Functor>
201  static void For(vtkIdType first, vtkIdType last, Functor const& f)
202  {
203  vtkSMPTools::For(first, last, 0, f);
204  }
206 
214  static void Initialize(int numThreads=0);
215 
217 
221  static int GetEstimatedNumberOfThreads();
222 };
224 
225 #endif
226 // 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:137
#define VTKCOMMONCORE_EXPORT
void For(vtkIdType first, vtkIdType last, vtkIdType grain)
Definition: vtkSMPTools.h:113
static void For(vtkIdType first, vtkIdType last, Functor const &f)
Definition: vtkSMPTools.h:201
int vtkIdType
Definition: vtkType.h:281
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:187
static void For(vtkIdType first, vtkIdType last, vtkIdType grain, Functor &f)
Definition: vtkSMPTools.h:157
A set of parallel (multi-threaded) utility functions.
Definition: vtkSMPTools.h:145
static void For(vtkIdType first, vtkIdType last, vtkIdType grain, Functor const &f)
Definition: vtkSMPTools.h:172
void For(vtkIdType first, vtkIdType last, vtkIdType grain)
Definition: vtkSMPTools.h:87
vtkSMPTools_FunctorInternal< Functor, init > type
Definition: vtkSMPTools.h:129