diff --git a/src/REPLICA/neb.cpp b/src/REPLICA/neb.cpp index f021a1f7fa..6e7b54660a 100644 --- a/src/REPLICA/neb.cpp +++ b/src/REPLICA/neb.cpp @@ -192,6 +192,8 @@ void NEB::run() update->endstep = update->laststep = update->firststep + n1steps; update->nsteps = n1steps; update->max_eval = n1steps; + if (update->laststep < 0 || update->laststep > MAXBIGINT) + error->all("Too many timesteps"); update->minimize->setup(); @@ -259,6 +261,8 @@ void NEB::run() update->endstep = update->laststep = update->firststep + n2steps; update->nsteps = n2steps; update->max_eval = n2steps; + if (update->laststep < 0 || update->laststep > MAXBIGINT) + error->all("Too many timesteps"); update->minimize->init(); fneb->rclimber = top; diff --git a/src/REPLICA/prd.cpp b/src/REPLICA/prd.cpp index 07ca60580e..95ebf5e9cb 100644 --- a/src/REPLICA/prd.cpp +++ b/src/REPLICA/prd.cpp @@ -210,6 +210,8 @@ void PRD::command(int narg, char **arg) update->beginstep = update->firststep = update->ntimestep; update->endstep = update->laststep = update->firststep + nsteps; update->restrict_output = 1; + if (update->laststep < 0 || update->laststep > MAXBIGINT) + error->all("Too many timesteps"); lmp->init(); @@ -495,6 +497,8 @@ void PRD::quench() update->whichflag = 2; update->nsteps = maxiter; update->endstep = update->laststep = update->firststep + maxiter; + if (update->laststep < 0 || update->laststep > MAXBIGINT) + error->all("Too many iterations"); // full init works diff --git a/src/REPLICA/tad.cpp b/src/REPLICA/tad.cpp index 0cbb937075..ad4602696f 100644 --- a/src/REPLICA/tad.cpp +++ b/src/REPLICA/tad.cpp @@ -195,6 +195,8 @@ void TAD::command(int narg, char **arg) update->beginstep = update->firststep = update->ntimestep; update->endstep = update->laststep = update->firststep + nsteps; update->restrict_output = 1; + if (update->laststep < 0 || update->laststep > MAXBIGINT) + error->all("Too many timesteps"); lmp->init(); @@ -460,6 +462,8 @@ void TAD::quench() update->whichflag = 2; update->nsteps = maxiter; update->endstep = update->laststep = update->firststep + maxiter; + if (update->laststep < 0 || update->laststep > MAXBIGINT) + error->all("Too many iterations"); // full init works diff --git a/src/REPLICA/temper.cpp b/src/REPLICA/temper.cpp index 17fcc41c76..4befb443b3 100644 --- a/src/REPLICA/temper.cpp +++ b/src/REPLICA/temper.cpp @@ -106,6 +106,8 @@ void Temper::command(int narg, char **arg) update->nsteps = nsteps; update->beginstep = update->firststep = update->ntimestep; update->endstep = update->laststep = update->firststep + nsteps; + if (update->laststep < 0 || update->laststep > MAXBIGINT) + error->all("Too many timesteps"); lmp->init(); diff --git a/src/fix_dt_reset.h b/src/fix_dt_reset.h index 7105dc442b..ddba09c73d 100644 --- a/src/fix_dt_reset.h +++ b/src/fix_dt_reset.h @@ -21,6 +21,7 @@ FixStyle(dt/reset,FixDtReset) #define LMP_FIX_DT_RESET_H #include "fix.h" +#include "lmptype.h" namespace LAMMPS_NS { @@ -36,7 +37,8 @@ class FixDtReset : public Fix { double compute_vector(int); private: - int minbound,maxbound,laststep; + bigint laststep; + int minbound,maxbound; double tmin,tmax,xmax; double ftm2v; double t_elapsed; diff --git a/src/lmptype.h b/src/lmptype.h index 84c135e248..6d45da2709 100644 --- a/src/lmptype.h +++ b/src/lmptype.h @@ -13,7 +13,7 @@ // define integer data types used by LAMMPS and associated size limits -// smallint = variables for system on 1 processor (nlocal, etc) +// smallint = variables for system on 1 processor (nlocal, nmax, etc) // tagint = variables for atom IDs (tag) // bigint = variables for total system (natoms, ntimestep, etc) @@ -31,8 +31,8 @@ // NOTE: if your machine/MPI does not support "long long" ints, // but only "long" ints, then you will likely need to set -// MPI_LMP_BIGINT to MPI_LONG, LLONG_MAX to LONG_MAX, -// "lld" to "ld", and ATOBIGINT to atol +// MPI_LONG_LONG to MPI_LONG, LLONG_MAX to LONG_MAX, +// "lld" to "ld", and atoll to atol #ifndef LMP_LMPTYPE_H #define LMP_LMPTYPE_H diff --git a/src/minimize.cpp b/src/minimize.cpp index 94d748f9dd..3d308b9de8 100644 --- a/src/minimize.cpp +++ b/src/minimize.cpp @@ -46,6 +46,8 @@ void Minimize::command(int narg, char **arg) update->whichflag = 2; update->beginstep = update->firststep = update->ntimestep; update->endstep = update->laststep = update->firststep + update->nsteps; + if (update->laststep < 0 || update->laststep > MAXBIGINT) + error->all("Too many iterations"); lmp->init(); update->minimize->setup(); diff --git a/src/run.cpp b/src/run.cpp index 63de1ec2a3..e5a1b318ea 100644 --- a/src/run.cpp +++ b/src/run.cpp @@ -14,6 +14,7 @@ #include "stdlib.h" #include "string.h" #include "run.h" +#include "lmptype.h" #include "domain.h" #include "update.h" #include "integrate.h" @@ -44,14 +45,14 @@ void Run::command(int narg, char **arg) if (domain->box_exist == 0) error->all("Run command before simulation box is defined"); - int nsteps = atoi(arg[0]); + bigint nsteps_input = ATOBIGINT(arg[0]); // parse optional args int uptoflag = 0; int startflag = 0; int stopflag = 0; - int start,stop; + bigint start,stop; int preflag = 1; int postflag = 1; int nevery = 0; @@ -67,12 +68,12 @@ void Run::command(int narg, char **arg) } else if (strcmp(arg[iarg],"start") == 0) { if (iarg+2 > narg) error->all("Illegal run command"); startflag = 1; - start = atoi(arg[iarg+1]); + start = ATOBIGINT(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"stop") == 0) { if (iarg+2 > narg) error->all("Illegal run command"); stopflag = 1; - stop = atoi(arg[iarg+1]); + stop = ATOBIGINT(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"pre") == 0) { if (iarg+2 > narg) error->all("Illegal run command"); @@ -103,9 +104,34 @@ void Run::command(int narg, char **arg) } else error->all("Illegal run command"); } - // adjust nsteps if upto was specified + // set nsteps as integer, using upto value if specified + + int nsteps; + if (!uptoflag) { + if (nsteps_input < 0 || nsteps_input > MAXSMALLINT) + error->all("Invalid run command N value"); + nsteps = static_cast (nsteps_input); + } else { + bigint delta = nsteps_input - update->ntimestep; + if (delta < 0 || delta > MAXSMALLINT) + error->all("Invalid run command upto value"); + nsteps = static_cast (delta); + } - if (uptoflag) nsteps -= update->ntimestep; + // error check + + if (startflag) { + if (start < 0 || start > MAXBIGINT) + error->all("Invalid run command start/stop value"); + if (start > update->ntimestep) + error->all("Run command start value is after start of run"); + } + if (stopflag) { + if (stop < 0 || stop > MAXBIGINT) + error->all("Invalid run command start/stop value"); + if (stop < update->ntimestep + nsteps) + error->all("Run command stop value is before end of run"); + } // if nevery, make copies of arg strings that are commands // required because re-parsing commands via input->one() will wipe out args @@ -122,15 +148,6 @@ void Run::command(int narg, char **arg) } } - // error check - - if (uptoflag && nsteps < 0) - error->all("Run command upto value is before current timestep"); - if (startflag && start > update->ntimestep) - error->all("Run command start value is after start of run"); - if (stopflag && stop < update->ntimestep + nsteps) - error->all("Run command stop value is before end of run"); - // perform a single run // use start/stop to set begin/end step // if pre or 1st run, do System init/setup, @@ -143,6 +160,8 @@ void Run::command(int narg, char **arg) update->nsteps = nsteps; update->firststep = update->ntimestep; update->laststep = update->ntimestep + nsteps; + if (update->laststep < 0 || update->laststep > MAXBIGINT) + error->all("Too many timesteps"); if (startflag) update->beginstep = start; else update->beginstep = update->firststep; @@ -181,6 +200,8 @@ void Run::command(int narg, char **arg) update->nsteps = nsteps; update->firststep = update->ntimestep; update->laststep = update->ntimestep + nsteps; + if (update->laststep < 0 || update->laststep > MAXBIGINT) + error->all("Too many timesteps"); if (startflag) update->beginstep = start; else update->beginstep = update->firststep;