$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 #ifndef LIBMESH_THREADS_ALLOCATORS_H 00020 #define LIBMESH_THREADS_ALLOCATORS_H 00021 00022 // Local includes 00023 #include "libmesh/libmesh_config.h" 00024 #include "libmesh/threads.h" 00025 00026 // Threading building blocks includes 00027 #ifdef LIBMESH_HAVE_TBB_API 00028 # include "tbb/scalable_allocator.h" 00029 #endif 00030 00031 // C++ includes 00032 #include <memory> // for std::allocator 00033 #include <cstddef> 00034 00035 namespace libMesh 00036 { 00037 00038 00043 namespace Threads 00044 { 00045 #ifdef LIBMESH_HAVE_TBB_API 00046 00047 //------------------------------------------------------------------- 00053 template <typename T> 00054 class scalable_allocator : public tbb::scalable_allocator<T> 00055 { 00056 public: 00057 typedef T* pointer; 00058 typedef const T* const_pointer; 00059 // typedef T& reference; // Intel 7.1 tries to instantiate an allocator<void>, 00060 // typedef const T& const_reference; // so we can't typedef a reference to void. 00061 typedef T value_type; 00062 typedef size_t size_type; 00063 typedef ptrdiff_t difference_type; 00064 00065 template<typename U> 00066 struct rebind 00067 { 00068 typedef scalable_allocator<U> other; 00069 }; 00070 00071 scalable_allocator () : 00072 tbb::scalable_allocator<T>() {} 00073 00074 scalable_allocator (const scalable_allocator &a) : 00075 tbb::scalable_allocator<T>(a) {} 00076 00077 template<typename U> 00078 scalable_allocator(const scalable_allocator<U> &a) : 00079 tbb::scalable_allocator<T>(a) {} 00080 }; 00081 00082 00083 00084 #else //LIBMESH_HAVE_TBB_API 00085 00086 00087 00088 //------------------------------------------------------------------- 00092 template <typename T> 00093 class scalable_allocator : public std::allocator<T> 00094 { 00095 public: 00096 typedef T* pointer; 00097 typedef const T* const_pointer; 00098 // typedef T& reference; // Intel 7.1 tries to instantiate an allocator<void>, 00099 // typedef const T& const_reference; // so we can't typedef a reference to void. 00100 typedef T value_type; 00101 typedef size_t size_type; 00102 typedef ptrdiff_t difference_type; 00103 00104 template<typename U> 00105 struct rebind 00106 { 00107 typedef scalable_allocator<U> other; 00108 }; 00109 00110 scalable_allocator () : 00111 std::allocator<T>() {} 00112 00113 scalable_allocator (const scalable_allocator &a) : 00114 std::allocator<T>(a) {} 00115 00116 template<typename U> 00117 scalable_allocator(const scalable_allocator<U> &a) : 00118 std::allocator<T>(a) {} 00119 }; 00120 00121 00122 #endif // #ifdef LIBMESH_HAVE_TBB_API 00123 00124 } // namespace Threads 00125 00126 } // namespace libMesh 00127 00128 #endif // LIBMESH_THREADS_ALLOCATORS_H