Ravelin
FastThreadable.h
1 #ifndef _RAVELIN_FAST_THREADABLE_H_
2 #define _RAVELIN_FAST_THREADABLE_H_
3 
4 #ifdef _OPENMP
5 #include <omp.h>
6 #include <vector>
7 #endif
8 
9 namespace Ravelin {
10 
12 template <class T>
14 {
15  private:
16  #ifdef _OPENMP
17  std::vector<T> _x;
18  #else
19  T _x;
20  #endif
21 
22  public:
24  {
25  #ifdef _OPENMP
26  _x.resize(omp_get_max_threads());
27  #endif
28  }
29 
30  T& operator()()
31  {
32  #ifdef _OPENMP
33  return _x[omp_get_thread_num()];
34  #else
35  return _x;
36  #endif
37  }
38 };
39 
40 } // end namespace
41 
42 #endif
43 
This class exists solely to make static declaration of dynamically allocated variables safe...
Definition: FastThreadable.h:13