diff --git a/src/compute_chunk_atom.cpp b/src/compute_chunk_atom.cpp index d83643b047..9a4c0c5c9e 100644 --- a/src/compute_chunk_atom.cpp +++ b/src/compute_chunk_atom.cpp @@ -548,7 +548,7 @@ void ComputeChunkAtom::compute_peratom() set lock, so that nchunk will not change from startstep to stopstep called by fix ave/chunk for duration of its Nfreq epoch OK if called by multiple fix ave/chunk commands - error if all callers do not have same duration + but error if all callers do not have same duration last caller holds the lock, so it can also unlock lockstop can be positive for final step of finite-size time window or can be -1 for infinite-size time window diff --git a/src/fix_ave_chunk.cpp b/src/fix_ave_chunk.cpp index 4f5ecc02ff..c173b0a8dc 100644 --- a/src/fix_ave_chunk.cpp +++ b/src/fix_ave_chunk.cpp @@ -297,7 +297,8 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) : } // increment lock counter in compute chunk/atom - // only if nrepeat > 1, so that locking spans multiple timesteps + // only if nrepeat > 1 or ave = RUNNING/WINDOW, + // so that locking spans multiple timesteps int icompute = modify->find_compute(idchunk); if (icompute < 0) @@ -305,7 +306,9 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) : cchunk = (ComputeChunkAtom *) modify->compute[icompute]; if (strcmp(cchunk->style,"chunk/atom") != 0) error->all(FLERR,"Fix ave/chunk does not use chunk/atom compute"); - if (nrepeat > 1) cchunk->lockcount++; + + if (nrepeat > 1 || ave == RUNNING || ave == WINDOW) cchunk->lockcount++; + if (ave == RUNNING || ave == WINDOW) cchunk->lock(this,update->ntimestep,-1); // print file comment lines @@ -409,10 +412,11 @@ FixAveChunk::~FixAveChunk() // decrement lock counter in compute chunk/atom, it if still exists - if (nrepeat > 1) { + if (nrepeat > 1 || ave == RUNNING || ave == WINDOW) { int icompute = modify->find_compute(idchunk); if (icompute >= 0) { cchunk = (ComputeChunkAtom *) modify->compute[icompute]; + if (ave == RUNNING || ave == WINDOW) cchunk->unlock(this); cchunk->lockcount--; } } @@ -515,8 +519,7 @@ void FixAveChunk::end_of_step() // zero out arrays that accumulate over many samples, but not across epochs // invoke setup_chunks() to determine current nchunk // re-allocate per-chunk arrays if needed - // then invoke lock() so nchunk cannot change until Nfreq epoch is over - // use final arg = -1 for infinite-time window + // invoke lock() so nchunk cannot change until Nfreq epoch is over // wrap setup_chunks in clearstep/addstep b/c it may invoke computes // both nevery and nfreq are future steps, // since call below to cchunk->ichunk() @@ -530,8 +533,8 @@ void FixAveChunk::end_of_step() modify->addstep_compute(ntimestep+nfreq); } allocate(); - if (ave == RUNNING || ave == WINDOW) cchunk->lock(this,ntimestep,-1); - else cchunk->lock(this,ntimestep,ntimestep+(nrepeat-1)*nevery); + if (nrepeat > 1 && ave == ONE) + cchunk->lock(this,ntimestep,ntimestep+(nrepeat-1)*nevery); for (m = 0; m < nchunk; m++) { count_many[m] = count_sum[m] = 0.0; for (i = 0; i < nvalues; i++) values_many[m][i] = 0.0; @@ -762,7 +765,7 @@ void FixAveChunk::end_of_step() // unlock compute chunk/atom at end of Nfreq epoch // do not unlock if ave = RUNNING or WINDOW - if (ave == ONE) cchunk->unlock(this); + if (nrepeat > 1 && ave == ONE) cchunk->unlock(this); // time average across samples // if normflag = ALL, final is total value / total count diff --git a/src/fix_ave_time.cpp b/src/fix_ave_time.cpp index a651a77813..c06825b71c 100644 --- a/src/fix_ave_time.cpp +++ b/src/fix_ave_time.cpp @@ -276,11 +276,14 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) : // enable locking of row count by this fix for computes of variable length // only if nrepeat > 1, so that locking spans multiple timesteps - if (any_variable_length && nrepeat > 1) { + if (any_variable_length && + (nrepeat > 1 || ave == RUNNING || ave == WINDOW)) { for (int i = 0; i < nvalues; i++) if (varlen[i]) { int icompute = modify->find_compute(ids[i]); modify->compute[icompute]->lock_enable(); + if (ave == RUNNING || ave == WINDOW) + modify->compute[icompute]->lock(this,update->ntimestep,-1); } } @@ -453,13 +456,17 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) : FixAveTime::~FixAveTime() { // decrement lock counter in compute chunk/atom, it if still exists - // NOTE: better comment - if (any_variable_length && nrepeat > 1) { + if (any_variable_length && + (nrepeat > 1 || ave == RUNNING || ave == WINDOW)) { for (int i = 0; i < nvalues; i++) if (varlen[i]) { int icompute = modify->find_compute(ids[i]); - if (icompute >= 0) modify->compute[icompute]->lock_disable(); + if (icompute >= 0) { + if (ave == RUNNING || ave == WINDOW) + modify->compute[icompute]->unlock(this); + modify->compute[icompute]->lock_disable(); + } } } @@ -732,9 +739,10 @@ void FixAveTime::invoke_vector(bigint ntimestep) bigint ntimestep = update->ntimestep; for (i = 0; i < nvalues; i++) { if (!varlen[i]) continue; - Compute *compute = modify->compute[value2index[i]]; - if (ave == RUNNING || ave == WINDOW) compute->lock(this,ntimestep,-1); - else compute->lock(this,ntimestep,ntimestep+(nrepeat-1)*nevery); + if (nrepeat > 1 && ave == ONE) { + Compute *compute = modify->compute[value2index[i]]; + compute->lock(this,ntimestep,ntimestep+(nrepeat-1)*nevery); + } } } @@ -817,7 +825,7 @@ void FixAveTime::invoke_vector(bigint ntimestep) // unlock any variable length computes at end of Nfreq epoch // do not unlock if ave = RUNNING or WINDOW - if (any_variable_length && ave == ONE) { + if (any_variable_length && nrepeat > 1 && ave == ONE) { for (i = 0; i < nvalues; i++) { if (!varlen[i]) continue; Compute *compute = modify->compute[value2index[i]];