From 4e247c3b8cc18f589956c646344de1eb7b53c37a Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 28 Aug 2015 23:36:43 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13951 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/USER-OMP/thr_data.cpp | 21 +++++++++++---------- src/USER-OMP/thr_omp.cpp | 12 ++++++++++++ src/fix_temp_berendsen.cpp | 4 ++++ src/fix_temp_csld.cpp | 4 ++++ src/fix_temp_csvr.cpp | 5 +++++ src/fix_temp_rescale.cpp | 7 +++++++ src/pair.h | 2 +- 7 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/USER-OMP/thr_data.cpp b/src/USER-OMP/thr_data.cpp index de09dadc58..21b3279e21 100644 --- a/src/USER-OMP/thr_data.cpp +++ b/src/USER-OMP/thr_data.cpp @@ -116,9 +116,10 @@ void ThrData::init_force(int nall, double **f, double **torque, void ThrData::init_eam(int nall, double *rho) { - _rho = rho + _tid*nall; - if (nall > 0) + if (nall >= 0 && rho) { + _rho = rho + _tid*nall; memset(_rho, 0, nall*sizeof(double)); + } } /* ---------------------------------------------------------------------- */ @@ -127,9 +128,9 @@ void ThrData::init_adp(int nall, double *rho, double **mu, double **lambda) { init_eam(nall, rho); - _mu = mu + _tid*nall; - _lambda = lambda + _tid*nall; - if (nall > 0) { + if (nall >= 0 && mu && lambda) { + _mu = mu + _tid*nall; + _lambda = lambda + _tid*nall; memset(&(_mu[0][0]), 0, nall*3*sizeof(double)); memset(&(_lambda[0][0]), 0, nall*6*sizeof(double)); } @@ -141,9 +142,9 @@ void ThrData::init_cdeam(int nall, double *rho, double *rhoB, double *D_values) { init_eam(nall, rho); - _rhoB = rhoB + _tid*nall; - _D_values = D_values + _tid*nall; - if (nall > 0) { + if (nall >= 0 && rhoB && D_values) { + _rhoB = rhoB + _tid*nall; + _D_values = D_values + _tid*nall; memset(_rhoB, 0, nall*sizeof(double)); memset(_D_values, 0, nall*sizeof(double)); } @@ -155,8 +156,8 @@ void ThrData::init_eim(int nall, double *rho, double *fp) { init_eam(nall, rho); - _fp = fp + _tid*nall; - if (nall > 0) + if (nall >= 0 && fp) + _fp = fp + _tid*nall; memset(_fp,0,nall*sizeof(double)); } diff --git a/src/USER-OMP/thr_omp.cpp b/src/USER-OMP/thr_omp.cpp index 4462f70bf1..ed3e82f539 100644 --- a/src/USER-OMP/thr_omp.cpp +++ b/src/USER-OMP/thr_omp.cpp @@ -513,6 +513,18 @@ void ThrOMP::ev_tally_thr(Pair * const pair, const int i, const int j, const int v_tally_thr(pair, i, j, nlocal, newton_pair, v, thr); } + + if (pair->num_tally_compute > 0) { + // ev_tally callbacks are not thread safe and thus have to be protected +#if defined(_OPENMP) +#pragma omp critical +#endif + for (int k=0; k < pair->num_tally_compute; ++k) { + Compute *c = pair->list_tally_compute[k]; + c->pair_tally_callback(i, j, nlocal, newton_pair, + evdwl, ecoul, fpair, delx, dely, delz); + } + } } /* ---------------------------------------------------------------------- diff --git a/src/fix_temp_berendsen.cpp b/src/fix_temp_berendsen.cpp index dc91056227..e4b2452455 100644 --- a/src/fix_temp_berendsen.cpp +++ b/src/fix_temp_berendsen.cpp @@ -138,6 +138,10 @@ void FixTempBerendsen::end_of_step() double t_current = temperature->compute_scalar(); double tdof = temperature->dof; + // there is nothing to do, if there are no degrees of freedom + + if (tdof < 1) return; + if (t_current == 0.0) error->all(FLERR, "Computed temperature for fix temp/berendsen cannot be 0.0"); diff --git a/src/fix_temp_csld.cpp b/src/fix_temp_csld.cpp index e394f06e58..28235b00fc 100644 --- a/src/fix_temp_csld.cpp +++ b/src/fix_temp_csld.cpp @@ -183,6 +183,10 @@ void FixTempCSLD::end_of_step() double t_current = temperature->compute_scalar(); double ekin_old = t_current * 0.5 * temperature->dof * force->boltz; + // there is nothing to do, if there are no degrees of freedom + + if (temperature->dof < 1) return; + double * const * const v = atom->v; const int * const mask = atom->mask; const int * const type = atom->type; diff --git a/src/fix_temp_csvr.cpp b/src/fix_temp_csvr.cpp index deaa8f91ec..6171e688c0 100644 --- a/src/fix_temp_csvr.cpp +++ b/src/fix_temp_csvr.cpp @@ -244,7 +244,12 @@ void FixTempCSVR::end_of_step() const double ekin_old = t_current * efactor; const double ekin_new = t_target * efactor; + // there is nothing to do, if there are no degrees of freedom + + if (temperature->dof < 1) return; + // compute velocity scaling factor on root node and broadcast + double lamda; if (comm->me == 0) { lamda = resamplekin(ekin_old, ekin_new); diff --git a/src/fix_temp_rescale.cpp b/src/fix_temp_rescale.cpp index 23c26aa02c..b84bab20c7 100644 --- a/src/fix_temp_rescale.cpp +++ b/src/fix_temp_rescale.cpp @@ -133,6 +133,13 @@ void FixTempRescale::init() void FixTempRescale::end_of_step() { double t_current = temperature->compute_scalar(); + + // there is nothing to do, if there are no degrees of freedom + + if (temperature->dof < 1) return; + + // protect against division by zero. + if (t_current == 0.0) error->all(FLERR,"Computed temperature for fix temp/rescale cannot be 0.0"); diff --git a/src/pair.h b/src/pair.h index 3d73fc1a93..d1a41fbee6 100644 --- a/src/pair.h +++ b/src/pair.h @@ -188,7 +188,7 @@ class Pair : protected Pointers { // management of callbacks to be run from ev_tally() - private: + protected: int num_tally_compute; class Compute **list_tally_compute; public: