plug small memory leak in USER-OMP variants of pppm kspace styles

This commit is contained in:
Axel Kohlmeyer
2017-07-17 23:56:38 -04:00
parent 23033404b0
commit c3a2ed0d1b
11 changed files with 111 additions and 128 deletions

View File

@ -54,6 +54,26 @@ PPPMCGOMP::PPPMCGOMP(LAMMPS *lmp, int narg, char **arg) :
suffix_flag |= Suffix::OMP;
}
/* ----------------------------------------------------------------------
clean up per-thread allocations
------------------------------------------------------------------------- */
PPPMCGOMP::~PPPMCGOMP()
{
#if defined(_OPENMP)
#pragma omp parallel default(none)
#endif
{
#if defined(_OPENMP)
const int tid = omp_get_thread_num();
#else
const int tid = 0;
#endif
ThrData *thr = fix->get_thr(tid);
thr->init_pppm(-order,memory);
}
}
/* ----------------------------------------------------------------------
allocate memory that depends on # of K-vectors and order
------------------------------------------------------------------------- */
@ -76,28 +96,6 @@ void PPPMCGOMP::allocate()
}
}
/* ----------------------------------------------------------------------
free memory that depends on # of K-vectors and order
------------------------------------------------------------------------- */
void PPPMCGOMP::deallocate()
{
PPPMCG::deallocate();
#if defined(_OPENMP)
#pragma omp parallel default(none)
#endif
{
#if defined(_OPENMP)
const int tid = omp_get_thread_num();
#else
const int tid = 0;
#endif
ThrData *thr = fix->get_thr(tid);
thr->init_pppm(-order,memory);
}
}
/* ----------------------------------------------------------------------
pre-compute modified (Hockney-Eastwood) Coulomb Green's function
------------------------------------------------------------------------- */

View File

@ -28,12 +28,11 @@ namespace LAMMPS_NS {
class PPPMCGOMP : public PPPMCG, public ThrOMP {
public:
PPPMCGOMP(class LAMMPS *, int, char **);
virtual ~PPPMCGOMP () {};
virtual ~PPPMCGOMP ();
virtual void compute(int, int);
protected:
virtual void allocate();
virtual void deallocate();
virtual void compute_gf_ik();
virtual void compute_gf_ad();

View File

@ -55,7 +55,24 @@ PPPMDispOMP::PPPMDispOMP(LAMMPS *lmp, int narg, char **arg) :
PPPMDispOMP::~PPPMDispOMP()
{
deallocate();
#if defined(_OPENMP)
#pragma omp parallel default(none)
#endif
{
#if defined(_OPENMP)
const int tid = omp_get_thread_num();
#else
const int tid = 0;
#endif
if (function[0]) {
ThrData * thr = fix->get_thr(tid);
thr->init_pppm(-order,memory);
}
if (function[1] + function[2]) {
ThrData * thr = fix->get_thr(tid);
thr->init_pppm_disp(-order_6,memory);
}
}
}
/* ----------------------------------------------------------------------
@ -87,34 +104,6 @@ void PPPMDispOMP::allocate()
}
}
/* ----------------------------------------------------------------------
free memory that depends on # of K-vectors and order
------------------------------------------------------------------------- */
void PPPMDispOMP::deallocate()
{
PPPMDisp::deallocate();
#if defined(_OPENMP)
#pragma omp parallel default(none)
#endif
{
#if defined(_OPENMP)
const int tid = omp_get_thread_num();
#else
const int tid = 0;
#endif
if (function[0]) {
ThrData * thr = fix->get_thr(tid);
thr->init_pppm(-order,memory);
}
if (function[1] + function[2]) {
ThrData * thr = fix->get_thr(tid);
thr->init_pppm_disp(-order_6,memory);
}
}
}
/* ----------------------------------------------------------------------
Compute the modified (hockney-eastwood) coulomb green function
------------------------------------------------------------------------- */

View File

@ -33,7 +33,6 @@ namespace LAMMPS_NS {
protected:
virtual void allocate();
virtual void deallocate();
virtual void compute_gf();
virtual void compute_gf_6();

View File

@ -52,6 +52,31 @@ PPPMDispTIP4POMP::PPPMDispTIP4POMP(LAMMPS *lmp, int narg, char **arg) :
suffix_flag |= Suffix::OMP;
}
/* ---------------------------------------------------------------------- */
PPPMDispTIP4POMP::~PPPMDispTIP4POMP()
{
#if defined(_OPENMP)
#pragma omp parallel default(none)
#endif
{
#if defined(_OPENMP)
const int tid = omp_get_thread_num();
#else
const int tid = 0;
#endif
if (function[0]) {
ThrData * thr = fix->get_thr(tid);
thr->init_pppm(-order,memory);
}
if (function[1] + function[2]) {
ThrData * thr = fix->get_thr(tid);
thr->init_pppm_disp(-order_6,memory);
}
}
}
/* ----------------------------------------------------------------------
allocate memory that depends on # of K-vectors and order
------------------------------------------------------------------------- */
@ -81,35 +106,6 @@ void PPPMDispTIP4POMP::allocate()
}
}
/* ----------------------------------------------------------------------
free memory that depends on # of K-vectors and order
------------------------------------------------------------------------- */
void PPPMDispTIP4POMP::deallocate()
{
PPPMDispTIP4P::deallocate();
#if defined(_OPENMP)
#pragma omp parallel default(none)
#endif
{
#if defined(_OPENMP)
const int tid = omp_get_thread_num();
#else
const int tid = 0;
#endif
if (function[0]) {
ThrData * thr = fix->get_thr(tid);
thr->init_pppm(-order,memory);
}
if (function[1] + function[2]) {
ThrData * thr = fix->get_thr(tid);
thr->init_pppm_disp(-order_6,memory);
}
}
}
/* ----------------------------------------------------------------------
Compute the modified (hockney-eastwood) coulomb green function
------------------------------------------------------------------------- */

View File

@ -28,11 +28,10 @@ namespace LAMMPS_NS {
class PPPMDispTIP4POMP : public PPPMDispTIP4P, public ThrOMP {
public:
PPPMDispTIP4POMP(class LAMMPS *, int, char **);
virtual ~PPPMDispTIP4POMP () {};
virtual ~PPPMDispTIP4POMP ();
protected:
virtual void allocate();
virtual void deallocate();
virtual void compute_gf();
virtual void compute_gf_6();

View File

@ -74,13 +74,11 @@ void PPPMOMP::allocate()
}
/* ----------------------------------------------------------------------
free memory that depends on # of K-vectors and order
clean up per-thread allocations
------------------------------------------------------------------------- */
void PPPMOMP::deallocate()
PPPMOMP::~PPPMOMP()
{
PPPM::deallocate();
#if defined(_OPENMP)
#pragma omp parallel default(none)
#endif

View File

@ -28,12 +28,11 @@ namespace LAMMPS_NS {
class PPPMOMP : public PPPM, public ThrOMP {
public:
PPPMOMP(class LAMMPS *, int, char **);
virtual ~PPPMOMP () {};
virtual ~PPPMOMP ();
virtual void compute(int, int);
protected:
virtual void allocate();
virtual void deallocate();
virtual void compute_gf_ik();
virtual void compute_gf_ad();

View File

@ -52,6 +52,26 @@ PPPMTIP4POMP::PPPMTIP4POMP(LAMMPS *lmp, int narg, char **arg) :
suffix_flag |= Suffix::OMP;
}
/* ----------------------------------------------------------------------
clean up per-thread allocations
------------------------------------------------------------------------- */
PPPMTIP4POMP::~PPPMTIP4POMP()
{
#if defined(_OPENMP)
#pragma omp parallel default(none)
#endif
{
#if defined(_OPENMP)
const int tid = omp_get_thread_num();
#else
const int tid = 0;
#endif
ThrData *thr = fix->get_thr(tid);
thr->init_pppm(-order,memory);
}
}
/* ----------------------------------------------------------------------
allocate memory that depends on # of K-vectors and order
------------------------------------------------------------------------- */
@ -74,28 +94,6 @@ void PPPMTIP4POMP::allocate()
}
}
/* ----------------------------------------------------------------------
free memory that depends on # of K-vectors and order
------------------------------------------------------------------------- */
void PPPMTIP4POMP::deallocate()
{
PPPMTIP4P::deallocate();
#if defined(_OPENMP)
#pragma omp parallel default(none)
#endif
{
#if defined(_OPENMP)
const int tid = omp_get_thread_num();
#else
const int tid = 0;
#endif
ThrData *thr = fix->get_thr(tid);
thr->init_pppm(-order,memory);
}
}
/* ----------------------------------------------------------------------
pre-compute modified (Hockney-Eastwood) Coulomb Green's function
------------------------------------------------------------------------- */

View File

@ -28,12 +28,11 @@ namespace LAMMPS_NS {
class PPPMTIP4POMP : public PPPMTIP4P, public ThrOMP {
public:
PPPMTIP4POMP(class LAMMPS *, int, char **);
virtual ~PPPMTIP4POMP () {};
virtual ~PPPMTIP4POMP ();
virtual void compute(int, int);
protected:
virtual void allocate();
virtual void deallocate();
virtual void compute_gf_ik();
virtual void compute_gf_ad();

View File

@ -176,16 +176,22 @@ void ThrData::init_pppm(int order, Memory *memory)
{
FFT_SCALAR **rho1d, **drho1d;
if (order > 0) {
memory->create2d_offset(rho1d,3,-order/2,order/2,"thr_data:rho1d");
memory->create2d_offset(drho1d,3,-order/2,order/2,"thr_data:drho1d");
_rho1d = static_cast<void *>(rho1d);
_drho1d = static_cast<void *>(drho1d);
rho1d = static_cast<FFT_SCALAR **>(_rho1d);
drho1d = static_cast<FFT_SCALAR **>(_drho1d);
if (rho1d) memory->destroy2d_offset(rho1d,-order/2);
if (drho1d) memory->destroy2d_offset(drho1d,-order/2);
memory->create2d_offset(rho1d,3,-order/2,order/2,"thr_data:rho1d");
memory->create2d_offset(drho1d,3,-order/2,order/2,"thr_data:drho1d");
_rho1d = static_cast<void *>(rho1d);
_drho1d = static_cast<void *>(drho1d);
} else {
order = -order;
rho1d = static_cast<FFT_SCALAR **>(_rho1d);
drho1d = static_cast<FFT_SCALAR **>(_drho1d);
memory->destroy2d_offset(rho1d,-order/2);
memory->destroy2d_offset(drho1d,-order/2);
if (rho1d) memory->destroy2d_offset(rho1d,-order/2);
if (drho1d) memory->destroy2d_offset(drho1d,-order/2);
_rho1d = NULL;
_drho1d = NULL;
}
}
@ -203,20 +209,23 @@ void ThrData::init_pppm_disp(int order_6, Memory *memory)
{
FFT_SCALAR **rho1d_6, **drho1d_6;
if (order_6 > 0) {
memory->create2d_offset(rho1d_6,3,-order_6/2,order_6/2,"thr_data:rho1d_6");
memory->create2d_offset(drho1d_6,3,-order_6/2,order_6/2,"thr_data:drho1d_6");
_rho1d_6 = static_cast<void *>(rho1d_6);
_drho1d_6 = static_cast<void *>(drho1d_6);
rho1d_6 = static_cast<FFT_SCALAR **>(_rho1d_6);
drho1d_6 = static_cast<FFT_SCALAR **>(_drho1d_6);
if (rho1d_6) memory->destroy2d_offset(rho1d_6,-order_6/2);
if (drho1d_6) memory->destroy2d_offset(drho1d_6,-order_6/2);
memory->create2d_offset(rho1d_6,3,-order_6/2,order_6/2,"thr_data:rho1d_6");
memory->create2d_offset(drho1d_6,3,-order_6/2,order_6/2,"thr_data:drho1d_6");
_rho1d_6 = static_cast<void *>(rho1d_6);
_drho1d_6 = static_cast<void *>(drho1d_6);
} else {
order_6 = -order_6;
rho1d_6 = static_cast<FFT_SCALAR **>(_rho1d_6);
drho1d_6 = static_cast<FFT_SCALAR **>(_drho1d_6);
memory->destroy2d_offset(rho1d_6,-order_6/2);
memory->destroy2d_offset(drho1d_6,-order_6/2);
if (rho1d_6) memory->destroy2d_offset(rho1d_6,-order_6/2);
if (drho1d_6) memory->destroy2d_offset(drho1d_6,-order_6/2);
}
}
/* ----------------------------------------------------------------------
compute global pair virial via summing F dot r over own & ghost atoms
at this point, only pairwise forces have been accumulated in atom->f