30 #ifndef SACADO_FAD_EXP_MEMPOOLSTORAGE_HPP 31 #define SACADO_FAD_EXP_MEMPOOLSTORAGE_HPP 33 #include <type_traits> 48 template <typename T, bool isScalar = IsScalarType<T>::value>
54 T* m =
static_cast<T*
>(pool->alloc());
56 for (
int i=0; i<sz; ++i)
67 T* m =
static_cast<T*
>(pool->
alloc());
69 for (
int i=0; i<sz; ++i)
83 T* m =
static_cast<T*
>(pool->
alloc());
85 for (
int i=0; i<sz; ++i)
86 new (p++)
T(*(src++));
94 static inline void copy(
const T* src,
T* dest,
int sz) {
95 for (
int i=0; i<sz; ++i)
100 static inline void zero(
T* dest,
int sz) {
101 for (
int i=0; i<sz; ++i)
108 for (
T* b = m; b!=e; b++)
110 pool->
free((
void*) m);
118 template <
typename T>
124 T* m =
static_cast<T*
>(pool->alloc());
134 T* m =
static_cast<T*
>(pool->
alloc());
135 std::memset(m,0,sz*
sizeof(
T));
148 T* m =
static_cast<T*
>(pool->
alloc());
150 for (
int i=0; i<sz; ++i)
151 new (p++)
T(*(src++));
159 static inline void copy(
const T* src,
T* dest,
int sz) {
160 std::memcpy(dest,src,sz*
sizeof(
T));
164 static inline void zero(
T* dest,
int sz) {
166 std::memset(dest,0,sz*
sizeof(
T));
171 pool->
free((
void*) m);
176 template <
typename T>
186 template <
typename TT>
370 #endif // SACADO_FAD_EXP_MEMPOOLSTORAGE_HPP
~MemPoolStorage()
Destructor.
MemPoolStorage< TT > type
KOKKOS_INLINE_FUNCTION MemPoolStorage()
Default constructor.
void zero()
Zero out derivative array.
static MemPool * defaultPool_
Default memory pool.
MemPoolStorage & operator=(const MemPoolStorage &x)
Assignment.
MemPoolStorage(const MemPoolStorage &x)
Copy constructor.
static T * get_and_fill(const T *src, int sz, MemPool *pool)
Get memory for new array of length sz and fill with entries from src.
static T * get_and_fill(int sz, MemPool *pool)
Get memory for new array of length sz and fill with zeros.
static constexpr int static_size
static void destroy_and_release(T *m, int sz, MemPool *pool)
Destroy array elements and release memory.
MemPoolStorage(const int sz, const T &x, const DerivInit zero_out)
Constructor with size sz.
void free(void *b)
Free an element.
int size() const
Returns number of derivative components.
const T & fastAccessDx(int i) const
Returns derivative component i without bounds checking.
MemPoolStorage(const T &x)
Constructor with value.
const T & val() const
Returns value.
#define KOKKOS_INLINE_FUNCTION
static T * get_and_fill(const T *src, int sz, MemPool *pool)
Get memory for new array of length sz and fill with entries from src.
static void copy(const T *src, T *dest, int sz)
Copy array from src to dest of length sz.
static constexpr bool is_statically_sized
static void zero(T *dest, int sz)
Zero out array dest of length sz.
Replace static derivative length.
Dynamic array allocation class that works for any type.
static T * get(int sz, MemPool *pool)
Get memory for new array of length sz.
std::remove_cv< T >::type value_type
T & fastAccessDx(int i)
Returns derivative component i without bounds checking.
const T * dx() const
Returns derivative array.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
T dx(int i) const
Returns derivative component i with bounds checking.
void expand(int sz)
Expand derivative array to size sz.
static void destroy_and_release(T *m, int sz, MemPool *pool)
Destroy array elements and release memory.
void resizeAndZero(int sz)
Resize the derivative array to sz.
MemPool * myPool_
Memory pool.
void resize(int sz)
Resize the derivative array to sz.
int len_
Derivative array length.
void * alloc()
Allocate a new element.
KOKKOS_INLINE_FUNCTION int length() const
Returns array length.
Initialize the derivative array.
Turn MemPoolStorage into a meta-function class usable with mpl::apply.
static T * get_and_fill(int sz, MemPool *pool)
Get memory for new array of length sz and fill with zeros.
int sz_
Derivative array size.
static void setDefaultPool(MemPool *pool)
Set the default memory pool for new objects.
static void copy(const T *src, T *dest, int sz)
Copy array from src to dest of length sz.
Derivative array storage class using dynamic memory allocation.
static void zero(T *dest, int sz)
Zero out array dest of length sz.