cast timestep related expressions to bigint before they can overflow

This commit is contained in:
Axel Kohlmeyer
2021-02-05 19:41:17 -05:00
parent 5036adeff0
commit e223ea3784
2 changed files with 6 additions and 6 deletions

View File

@ -374,7 +374,7 @@ void FixAveAtom::end_of_step()
} }
irepeat = 0; irepeat = 0;
nvalid = ntimestep+peratom_freq - (nrepeat-1)*nevery; nvalid = ntimestep+peratom_freq - ((bigint)nrepeat-1)*nevery;
modify->addstep_compute(nvalid); modify->addstep_compute(nvalid);
if (array == nullptr) return; if (array == nullptr) return;
@ -394,7 +394,7 @@ void FixAveAtom::end_of_step()
double FixAveAtom::memory_usage() double FixAveAtom::memory_usage()
{ {
double bytes; double bytes;
bytes = atom->nmax*nvalues * sizeof(double); bytes = (double)atom->nmax*nvalues * sizeof(double);
return bytes; return bytes;
} }
@ -452,7 +452,7 @@ bigint FixAveAtom::nextvalid()
if (nvalid-peratom_freq == update->ntimestep && nrepeat == 1) if (nvalid-peratom_freq == update->ntimestep && nrepeat == 1)
nvalid = update->ntimestep; nvalid = update->ntimestep;
else else
nvalid -= (nrepeat-1)*nevery; nvalid -= ((bigint)nrepeat-1)*nevery;
if (nvalid < update->ntimestep) nvalid += peratom_freq; if (nvalid < update->ntimestep) nvalid += peratom_freq;
return nvalid; return nvalid;
} }

View File

@ -583,7 +583,7 @@ void FixAveChunk::end_of_step()
} }
allocate(); allocate();
if (nrepeat > 1 && ave == ONE) if (nrepeat > 1 && ave == ONE)
cchunk->lock(this,ntimestep,ntimestep+(nrepeat-1)*nevery); cchunk->lock(this,ntimestep,ntimestep+((bigint)nrepeat-1)*nevery);
else if ((ave == RUNNING || ave == WINDOW) && !lockforever) { else if ((ave == RUNNING || ave == WINDOW) && !lockforever) {
cchunk->lock(this,update->ntimestep,-1); cchunk->lock(this,update->ntimestep,-1);
lockforever = 1; lockforever = 1;
@ -841,7 +841,7 @@ void FixAveChunk::end_of_step()
} }
irepeat = 0; irepeat = 0;
nvalid = ntimestep+nfreq - (nrepeat-1)*nevery; nvalid = ntimestep+nfreq - ((bigint)nrepeat-1)*nevery;
modify->addstep_compute(nvalid); modify->addstep_compute(nvalid);
// unlock compute chunk/atom at end of Nfreq epoch // unlock compute chunk/atom at end of Nfreq epoch
@ -1120,7 +1120,7 @@ bigint FixAveChunk::nextvalid()
if (nvalid-nfreq == update->ntimestep && nrepeat == 1) if (nvalid-nfreq == update->ntimestep && nrepeat == 1)
nvalid = update->ntimestep; nvalid = update->ntimestep;
else else
nvalid -= (nrepeat-1)*nevery; nvalid -= ((bigint)nrepeat-1)*nevery;
if (nvalid < update->ntimestep) nvalid += nfreq; if (nvalid < update->ntimestep) nvalid += nfreq;
return nvalid; return nvalid;
} }