diff --git a/src/USER-OMP/pppm_cg_omp.cpp b/src/USER-OMP/pppm_cg_omp.cpp index 021765d14b..df0e632f78 100644 --- a/src/USER-OMP/pppm_cg_omp.cpp +++ b/src/USER-OMP/pppm_cg_omp.cpp @@ -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 ------------------------------------------------------------------------- */ diff --git a/src/USER-OMP/pppm_cg_omp.h b/src/USER-OMP/pppm_cg_omp.h index 91f09ebbfa..07763eba38 100644 --- a/src/USER-OMP/pppm_cg_omp.h +++ b/src/USER-OMP/pppm_cg_omp.h @@ -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(); diff --git a/src/USER-OMP/pppm_disp_omp.cpp b/src/USER-OMP/pppm_disp_omp.cpp index 16d3001ddf..6cf2983761 100644 --- a/src/USER-OMP/pppm_disp_omp.cpp +++ b/src/USER-OMP/pppm_disp_omp.cpp @@ -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 ------------------------------------------------------------------------- */ diff --git a/src/USER-OMP/pppm_disp_omp.h b/src/USER-OMP/pppm_disp_omp.h index 86c213282a..b1ec2856bb 100644 --- a/src/USER-OMP/pppm_disp_omp.h +++ b/src/USER-OMP/pppm_disp_omp.h @@ -33,7 +33,6 @@ namespace LAMMPS_NS { protected: virtual void allocate(); - virtual void deallocate(); virtual void compute_gf(); virtual void compute_gf_6(); diff --git a/src/USER-OMP/pppm_disp_tip4p_omp.cpp b/src/USER-OMP/pppm_disp_tip4p_omp.cpp index 8872c849f3..29aeeb79dc 100644 --- a/src/USER-OMP/pppm_disp_tip4p_omp.cpp +++ b/src/USER-OMP/pppm_disp_tip4p_omp.cpp @@ -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 ------------------------------------------------------------------------- */ diff --git a/src/USER-OMP/pppm_disp_tip4p_omp.h b/src/USER-OMP/pppm_disp_tip4p_omp.h index e05a52ac80..296444366b 100644 --- a/src/USER-OMP/pppm_disp_tip4p_omp.h +++ b/src/USER-OMP/pppm_disp_tip4p_omp.h @@ -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(); diff --git a/src/USER-OMP/pppm_omp.cpp b/src/USER-OMP/pppm_omp.cpp index a62199be56..48b91e3a7b 100644 --- a/src/USER-OMP/pppm_omp.cpp +++ b/src/USER-OMP/pppm_omp.cpp @@ -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 diff --git a/src/USER-OMP/pppm_omp.h b/src/USER-OMP/pppm_omp.h index 03eb0e110b..bf8a9e0c21 100644 --- a/src/USER-OMP/pppm_omp.h +++ b/src/USER-OMP/pppm_omp.h @@ -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(); diff --git a/src/USER-OMP/pppm_tip4p_omp.cpp b/src/USER-OMP/pppm_tip4p_omp.cpp index 21e3081c65..1eab140cec 100644 --- a/src/USER-OMP/pppm_tip4p_omp.cpp +++ b/src/USER-OMP/pppm_tip4p_omp.cpp @@ -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 ------------------------------------------------------------------------- */ diff --git a/src/USER-OMP/pppm_tip4p_omp.h b/src/USER-OMP/pppm_tip4p_omp.h index 0ee807651c..59559cd587 100644 --- a/src/USER-OMP/pppm_tip4p_omp.h +++ b/src/USER-OMP/pppm_tip4p_omp.h @@ -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(); diff --git a/src/USER-OMP/thr_data.cpp b/src/USER-OMP/thr_data.cpp index 28fd27f9b8..2ee68fb311 100644 --- a/src/USER-OMP/thr_data.cpp +++ b/src/USER-OMP/thr_data.cpp @@ -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(rho1d); - _drho1d = static_cast(drho1d); + rho1d = static_cast(_rho1d); + drho1d = static_cast(_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(rho1d); + _drho1d = static_cast(drho1d); } else { order = -order; rho1d = static_cast(_rho1d); drho1d = static_cast(_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(rho1d_6); - _drho1d_6 = static_cast(drho1d_6); + rho1d_6 = static_cast(_rho1d_6); + drho1d_6 = static_cast(_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(rho1d_6); + _drho1d_6 = static_cast(drho1d_6); } else { order_6 = -order_6; rho1d_6 = static_cast(_rho1d_6); drho1d_6 = static_cast(_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