threads_allocators.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 #ifndef LIBMESH_THREADS_ALLOCATORS_H
20 #define LIBMESH_THREADS_ALLOCATORS_H
21 
22 // Local includes
23 #include "libmesh/libmesh_config.h"
24 #include "libmesh/threads.h"
25 
26 // Threading building blocks includes
27 #ifdef LIBMESH_HAVE_TBB_API
28 # include "libmesh/ignore_warnings.h"
29 # include "tbb/scalable_allocator.h"
31 #endif
32 
33 // C++ includes
34 #include <memory> // for std::allocator
35 #include <cstddef> // std::ptrdiff_t
36 
37 namespace libMesh
38 {
39 
40 
45 namespace Threads
46 {
47 #ifdef LIBMESH_HAVE_TBB_API
48 
49 //-------------------------------------------------------------------
55 template <typename T>
56 class scalable_allocator : public tbb::scalable_allocator<T>
57 {
58 public:
59  typedef T * pointer;
60  typedef const T * const_pointer;
61  // typedef T & reference; // Intel 7.1 tries to instantiate an allocator<void>,
62  // typedef const T & const_reference; // so we can't typedef a reference to void.
63  typedef T value_type;
64  typedef size_t size_type;
65  typedef std::ptrdiff_t difference_type;
66 
67  template<typename U>
68  struct rebind
69  {
71  };
72 
74  tbb::scalable_allocator<T>() {}
75 
77  tbb::scalable_allocator<T>(a) {}
78 
79  template<typename U>
81  tbb::scalable_allocator<T>(a) {}
82 };
83 
84 
85 
86 #else //LIBMESH_HAVE_TBB_API
87 
88 
89 
90 //-------------------------------------------------------------------
94 template <typename T>
95 class scalable_allocator : public std::allocator<T>
96 {
97 public:
98  typedef T * pointer;
99  typedef const T * const_pointer;
100  // typedef T & reference; // Intel 7.1 tries to instantiate an allocator<void>,
101  // typedef const T & const_reference; // so we can't typedef a reference to void.
102  typedef T value_type;
103  typedef size_t size_type;
104  typedef std::ptrdiff_t difference_type;
105 
106  template<typename U>
107  struct rebind
108  {
110  };
111 
113  std::allocator<T>() {}
114 
116  std::allocator<T>(a) {}
117 
118  template<typename U>
120  std::allocator<T>(a) {}
121 };
122 
123 
124 #endif // #ifdef LIBMESH_HAVE_TBB_API
125 
126 } // namespace Threads
127 
128 } // namespace libMesh
129 
130 #endif // LIBMESH_THREADS_ALLOCATORS_H
scalable_allocator(const scalable_allocator< U > &a)
scalable_allocator(const scalable_allocator &a)