diff --git a/src/accelerator_kokkos.h b/src/accelerator_kokkos.h index dc8bf5d9be..2c542b74fd 100644 --- a/src/accelerator_kokkos.h +++ b/src/accelerator_kokkos.h @@ -82,6 +82,12 @@ class ModifyKokkos : public Modify { ~ModifyKokkos() {} }; +class DAT { + public: + typedef double tdual_xfloat_1d; + typedef int tdual_int_2d; +}; + } #endif diff --git a/src/fix.cpp b/src/fix.cpp index 332e3c8aea..60e11de5aa 100644 --- a/src/fix.cpp +++ b/src/fix.cpp @@ -91,15 +91,19 @@ Fix::Fix(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) execution_space = Host; datamask_read = ALL_MASK; datamask_modify = ALL_MASK; + + copymode = 0; } /* ---------------------------------------------------------------------- */ Fix::~Fix() { - delete [] id; - delete [] style; - memory->destroy(vatom); + if (!copymode) { + delete [] id; + delete [] style; + memory->destroy(vatom); + } } /* ---------------------------------------------------------------------- diff --git a/src/fix.h b/src/fix.h index b762f99029..56ff4d0fd1 100644 --- a/src/fix.h +++ b/src/fix.h @@ -209,6 +209,9 @@ class Fix : protected Pointers { int vflag_global,vflag_atom; int maxvatom; + int copymode; // if set, do not deallocate during destruction + // required when classes are used as functors by Kokkos + void v_setup(int); void v_tally(int, int *, double, double *); diff --git a/src/pair.cpp b/src/pair.cpp index 42ad10032b..27811567c4 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -104,14 +104,18 @@ Pair::Pair(LAMMPS *lmp) : Pointers(lmp) execution_space = Host; datamask_read = ALL_MASK; datamask_modify = ALL_MASK; + + copymode = 0; } /* ---------------------------------------------------------------------- */ Pair::~Pair() { - memory->destroy(eatom); - memory->destroy(vatom); + if (!copymode) { + memory->destroy(eatom); + memory->destroy(vatom); + } } /* ---------------------------------------------------------------------- diff --git a/src/pair.h b/src/pair.h index d58b79de9d..e7278a0d70 100644 --- a/src/pair.h +++ b/src/pair.h @@ -15,6 +15,7 @@ #define LMP_PAIR_H #include "pointers.h" +#include "accelerator_kokkos.h" namespace LAMMPS_NS { @@ -167,6 +168,8 @@ class Pair : protected Pointers { virtual int pack_forward_comm(int, int *, double *, int, int *) {return 0;} virtual void unpack_forward_comm(int, int, double *) {} + virtual int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, int, int *) {return 0;}; + virtual void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) {} virtual int pack_reverse_comm(int, int, double *) {return 0;} virtual void unpack_reverse_comm(int, int *, double *) {} virtual double memory_usage(); @@ -207,6 +210,9 @@ class Pair : protected Pointers { int vflag_fdotr; int maxeatom,maxvatom; + int copymode; // if set, do not deallocate during destruction + // required when classes are used as functors by Kokkos + virtual void ev_setup(int, int); void ev_unset(); void ev_tally_full(int, double, double, double, double, double, double); diff --git a/src/pair_buck.cpp b/src/pair_buck.cpp index 096d4d0ff6..5eaadd72c9 100644 --- a/src/pair_buck.cpp +++ b/src/pair_buck.cpp @@ -38,7 +38,7 @@ PairBuck::PairBuck(LAMMPS *lmp) : Pair(lmp) PairBuck::~PairBuck() { - if (allocated) { + if (allocated && !copymode) { memory->destroy(setflag); memory->destroy(cutsq); diff --git a/src/pair_buck.h b/src/pair_buck.h index bdcb1560eb..d74934de82 100644 --- a/src/pair_buck.h +++ b/src/pair_buck.h @@ -47,7 +47,7 @@ class PairBuck : public Pair { double **a,**rho,**c; double **rhoinv,**buck1,**buck2,**offset; - void allocate(); + virtual void allocate(); }; } diff --git a/src/pair_coul_dsf.cpp b/src/pair_coul_dsf.cpp index 0aba5548db..17b3dfaa71 100644 --- a/src/pair_coul_dsf.cpp +++ b/src/pair_coul_dsf.cpp @@ -52,7 +52,7 @@ PairCoulDSF::PairCoulDSF(LAMMPS *lmp) : Pair(lmp) PairCoulDSF::~PairCoulDSF() { - if (allocated) { + if (allocated && !copymode) { memory->destroy(setflag); memory->destroy(cutsq); } diff --git a/src/pair_coul_wolf.cpp b/src/pair_coul_wolf.cpp index 799b672a4e..4687a75fc4 100644 --- a/src/pair_coul_wolf.cpp +++ b/src/pair_coul_wolf.cpp @@ -43,7 +43,7 @@ PairCoulWolf::PairCoulWolf(LAMMPS *lmp) : Pair(lmp) PairCoulWolf::~PairCoulWolf() { - if (allocated) { + if (allocated && !copymode) { memory->destroy(setflag); memory->destroy(cutsq); }