forked from lijiext/lammps
git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@11532 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
parent
b28ce4b3bb
commit
82833b729f
50
src/memory.h
50
src/memory.h
|
@ -16,6 +16,9 @@
|
|||
|
||||
#include "lmptype.h"
|
||||
#include "pointers.h"
|
||||
#ifdef LMP_KOKKOS
|
||||
#include "kokkos_type.h"
|
||||
#endif
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
|
@ -28,10 +31,17 @@ class Memory : protected Pointers {
|
|||
void sfree(void *);
|
||||
void fail(const char *);
|
||||
|
||||
// Kokkos memory allocation functions
|
||||
|
||||
#ifdef LMP_KOKKOS
|
||||
#include "memory_kokkos.h"
|
||||
#endif
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
create/grow/destroy vecs and multidim arrays with contiguous memory blocks
|
||||
only use with primitive data types, e.g. 1d vec of ints, 2d array of doubles
|
||||
cannot use with pointers, e.g. 1d vec of int*, due to mismatched destroy
|
||||
fail() prevents use with pointers,
|
||||
e.g. 1d vec of int*, due to mismatched destroy
|
||||
avoid use with non-primitive data types to avoid code bloat
|
||||
for these other cases, use smalloc/srealloc/sfree directly
|
||||
------------------------------------------------------------------------- */
|
||||
|
@ -49,7 +59,8 @@ class Memory : protected Pointers {
|
|||
}
|
||||
|
||||
template <typename TYPE>
|
||||
TYPE **create(TYPE **&array, int n, const char *name) {fail(name);}
|
||||
TYPE **create(TYPE **&array, int n, const char *name)
|
||||
{fail(name); return NULL;}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
grow or shrink 1d array
|
||||
|
@ -66,7 +77,8 @@ class Memory : protected Pointers {
|
|||
}
|
||||
|
||||
template <typename TYPE>
|
||||
TYPE **grow(TYPE **&array, int n, const char *name) {fail(name);}
|
||||
TYPE **grow(TYPE **&array, int n, const char *name)
|
||||
{fail(name); return NULL;}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
destroy a 1d array
|
||||
|
@ -74,9 +86,7 @@ class Memory : protected Pointers {
|
|||
|
||||
template <typename TYPE>
|
||||
void destroy(TYPE *array)
|
||||
{
|
||||
sfree(array);
|
||||
}
|
||||
{sfree(array);}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
create a 1d array with index from nlo to nhi inclusive
|
||||
|
@ -94,7 +104,7 @@ class Memory : protected Pointers {
|
|||
|
||||
template <typename TYPE>
|
||||
TYPE **create1d_offset(TYPE **&array, int nlo, int nhi, const char *name)
|
||||
{fail(name);}
|
||||
{fail(name); return NULL;}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
destroy a 1d array with index offset
|
||||
|
@ -128,7 +138,7 @@ class Memory : protected Pointers {
|
|||
|
||||
template <typename TYPE>
|
||||
TYPE ***create(TYPE ***&array, int n1, int n2, const char *name)
|
||||
{fail(name);}
|
||||
{fail(name); return NULL;}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
grow or shrink 1st dim of a 2d array
|
||||
|
@ -155,7 +165,7 @@ class Memory : protected Pointers {
|
|||
|
||||
template <typename TYPE>
|
||||
TYPE ***grow(TYPE ***&array, int n1, int n2, const char *name)
|
||||
{fail(name);}
|
||||
{fail(name); return NULL;}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
destroy a 2d array
|
||||
|
@ -194,7 +204,7 @@ class Memory : protected Pointers {
|
|||
|
||||
template <typename TYPE>
|
||||
TYPE ***create_ragged(TYPE ***&array, int n1, int *n2, const char *name)
|
||||
{fail(name);}
|
||||
{fail(name); return NULL;}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
create a 2d array with 2nd index from n2lo to n2hi inclusive
|
||||
|
@ -213,7 +223,7 @@ class Memory : protected Pointers {
|
|||
|
||||
template <typename TYPE>
|
||||
TYPE ***create2d_offset(TYPE ***&array, int n1, int n2lo, int n2hi,
|
||||
const char *name) {fail(name);}
|
||||
const char *name) {fail(name); return NULL;}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
destroy a 2d array with 2nd index offset
|
||||
|
@ -257,7 +267,7 @@ class Memory : protected Pointers {
|
|||
|
||||
template <typename TYPE>
|
||||
TYPE ****create(TYPE ****&array, int n1, int n2, int n3, const char *name)
|
||||
{fail(name);}
|
||||
{fail(name); return NULL;}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
grow or shrink 1st dim of a 3d array
|
||||
|
@ -292,7 +302,7 @@ class Memory : protected Pointers {
|
|||
|
||||
template <typename TYPE>
|
||||
TYPE ****grow(TYPE ****&array, int n1, int n2, int n3, const char *name)
|
||||
{fail(name);}
|
||||
{fail(name); return NULL;}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
destroy a 3d array
|
||||
|
@ -325,7 +335,7 @@ class Memory : protected Pointers {
|
|||
template <typename TYPE>
|
||||
TYPE ****create3d_offset(TYPE ****&array, int n1lo, int n1hi,
|
||||
int n2, int n3, const char *name)
|
||||
{fail(name);}
|
||||
{fail(name); return NULL;}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
free a 3d array with 1st index offset
|
||||
|
@ -366,7 +376,7 @@ class Memory : protected Pointers {
|
|||
TYPE ****create3d_offset(TYPE ****&array, int n1lo, int n1hi,
|
||||
int n2lo, int n2hi, int n3lo, int n3hi,
|
||||
const char *name)
|
||||
{fail(name);}
|
||||
{fail(name); return NULL;}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
free a 3d array with all 3 indices offset
|
||||
|
@ -422,7 +432,7 @@ class Memory : protected Pointers {
|
|||
template <typename TYPE>
|
||||
TYPE *****create(TYPE *****&array, int n1, int n2, int n3, int n4,
|
||||
const char *name)
|
||||
{fail(name);}
|
||||
{fail(name); return NULL;}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
destroy a 4d array
|
||||
|
@ -468,13 +478,15 @@ class Memory : protected Pointers {
|
|||
TYPE ****create4d_offset(TYPE *****&array, int n1, int n2lo, int n2hi,
|
||||
int n3lo, int n3hi, int n4lo, int n4hi,
|
||||
const char *name)
|
||||
{fail(name);}
|
||||
{fail(name); return NULL;}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
free a 4d array with indices 2,3, and 4 offset
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
template <typename TYPE>
|
||||
void destroy4d_offset(TYPE ****array, int n2_offset, int n3_offset, int n4_offset)
|
||||
void destroy4d_offset(TYPE ****array,
|
||||
int n2_offset, int n3_offset, int n4_offset)
|
||||
{
|
||||
if (array == NULL) return;
|
||||
sfree(&array[0][n2_offset][n3_offset][n4_offset]);
|
||||
|
@ -532,7 +544,7 @@ class Memory : protected Pointers {
|
|||
template <typename TYPE>
|
||||
TYPE ******create(TYPE ******&array, int n1, int n2, int n3, int n4,
|
||||
int n5, const char *name)
|
||||
{fail(name);}
|
||||
{fail(name); return NULL;}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
destroy a 5d array
|
||||
|
|
Loading…
Reference in New Issue