add -skiprun command line flag that sets a timeout so that run and minimizations loops are skipped

This commit is contained in:
Axel Kohlmeyer
2021-09-03 11:21:42 -04:00
parent bca9157405
commit f768b701ee
4 changed files with 126 additions and 94 deletions

View File

@ -1,15 +1,30 @@
LAMMPS input scripts
====================
LAMMPS executes by reading commands from a input script (text file),
one line at a time. When the input script ends, LAMMPS exits. Each
command causes LAMMPS to take some action. It may set an internal
variable, read in a file, or run a simulation. Most commands have
default settings, which means you only need to use the command if you
wish to change the default.
LAMMPS executes calculations by reading commands from a input script (text file), one
line at a time. When the input script ends, LAMMPS exits. This is different
from programs that read and process the entire input before starting a calculation.
Each command causes LAMMPS to take some immediate action without regard
for any commands that may be processed later. Commands may set an
internal variable, read in a file, or run a simulation. These actions
can be grouped into three categories:
a) commands that change a global setting (examples: timestep, newton,
echo, log, thermo, restart),
b) commands that add, modify, remove, or replace "styles" that are
executed during a "run" (examples: pair_style, fix, compute, dump,
thermo_style, pair_modify), and
c) commands that execute a "run" or perform some other computation or
operation (examples: print, run, minimize, temper, write_dump, rerun,
read_data, read_restart)
Commands in category a) have default settings, which means you only
need to use the command if you wish to change the defaults.
In many cases, the ordering of commands in an input script is not
important. However the following rules apply:
important, but can have consequences when the global state is changed
between commands in the c) category. The following rules apply:
(1) LAMMPS does not read your entire input script and then perform a
simulation with all the settings. Rather, the input script is read
@ -32,24 +47,29 @@ does something different than this sequence:
In the first case, the specified timestep (0.5 fs) is used for two
simulations of 100 timesteps each. In the second case, the default
timestep (1.0 fs) is used for the first 100 step simulation and a 0.5 fs
timestep is used for the second one.
timestep (1.0 fs) is used for the first 100 step simulation and a
0.5 fs timestep is used for the second one.
(2) Some commands are only valid when they follow other commands. For
example you cannot set the temperature of a group of atoms until atoms
have been defined and a group command is used to define which atoms
belong to the group.
example you cannot set the temperature of a group of atoms until
atoms have been defined and a group command is used to define which
atoms belong to the group.
(3) Sometimes command B will use values that can be set by command A.
This means command A must precede command B in the input script if it
is to have the desired effect. For example, the
:doc:`read_data <read_data>` command initializes the system by setting
up the simulation box and assigning atoms to processors. If default
values are not desired, the :doc:`processors <processors>` and
:doc:`boundary <boundary>` commands need to be used before read_data to
tell LAMMPS how to map processors to the simulation box.
This means command A must precede command B in the input script if
it is to have the desired effect. For example, the :doc:`read_data
<read_data>` command initializes the system by setting up the
simulation box and assigning atoms to processors. If default values
are not desired, the :doc:`processors <processors>` and
:doc:`boundary <boundary>` commands need to be used before read_data
to tell LAMMPS how to map processors to the simulation box.
Many input script errors are detected by LAMMPS and an ERROR or
WARNING message is printed. The :doc:`Errors <Errors>` page gives
more information on what errors mean. The documentation for each
command lists restrictions on how the command can be used.
You can use the :ref:`-skiprun <skiprun>` command line flag
to have LAMMPS skip the execution of any "run", "minimize", or similar
commands to check the entire input for correct syntax to avoid crashes
on typos or syntax errors in long runs.

View File

@ -2,7 +2,7 @@ Command-line options
====================
At run time, LAMMPS recognizes several optional command-line switches
which may be used in any order. Either the full word or a one-or-two
which may be used in any order. Either the full word or a one or two
letter abbreviation can be used:
* :ref:`-e or -echo <echo>`
@ -22,6 +22,7 @@ letter abbreviation can be used:
* :ref:`-r2data or -restart2data <restart2data>`
* :ref:`-r2dump or -restart2dump <restart2dump>`
* :ref:`-sc or -screen <screen>`
* :ref:`-sr or skiprun <skiprun>`
* :ref:`-sf or -suffix <suffix>`
* :ref:`-v or -var <var>`
@ -532,6 +533,20 @@ partition screen files file.N.
----------
.. _skiprun:
**-skiprun**
Insert the command :doc:`timer timerout 0 every 1 <timer>` at the
beginning of an input file or after a :doc:`clear <clear>` command.
This has the effect that the entire LAMMPS input script is processed
without executing actual runs or minimizations (their main loops are
skipped). This can be helpful and convenient to test input scripts for
long running calculations to avoid having them crash after a long time
due to a typo or syntax error.
----------
.. _suffix:
**-suffix style args**

View File

@ -126,6 +126,8 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
cslib = nullptr;
cscomm = 0;
skipflag = 0;
screen = nullptr;
logfile = nullptr;
infile = nullptr;
@ -391,6 +393,11 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
screenflag = iarg + 1;
iarg += 2;
} else if (strcmp(arg[iarg],"-skiprun") == 0 ||
strcmp(arg[iarg],"-sr") == 0) {
skipflag = 1;
++iarg;
} else if (strcmp(arg[iarg],"-suffix") == 0 ||
strcmp(arg[iarg],"-sf") == 0) {
if (iarg+2 > narg)
@ -462,9 +469,8 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
else {
universe->uscreen = fopen(arg[screenflag],"w");
if (universe->uscreen == nullptr)
error->universe_one(FLERR,fmt::format("Cannot open universe screen "
"file {}: {}",arg[screenflag],
utils::getsyserror()));
error->universe_one(FLERR,fmt::format("Cannot open universe screen file {}: {}",
arg[screenflag],utils::getsyserror()));
}
if (logflag == 0) {
if (helpflag == 0) {
@ -478,9 +484,8 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
else {
universe->ulogfile = fopen(arg[logflag],"w");
if (universe->ulogfile == nullptr)
error->universe_one(FLERR,fmt::format("Cannot open universe log "
"file {}: {}",arg[logflag],
utils::getsyserror()));
error->universe_one(FLERR,fmt::format("Cannot open universe log file {}: {}",
arg[logflag],utils::getsyserror()));
}
}
@ -505,8 +510,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
else if (strcmp(arg[inflag], "none") == 0) infile = stdin;
else infile = fopen(arg[inflag],"r");
if (infile == nullptr)
error->one(FLERR,"Cannot open input script {}: {}",
arg[inflag], utils::getsyserror());
error->one(FLERR,"Cannot open input script {}: {}",arg[inflag], utils::getsyserror());
}
if ((universe->me == 0) && !helpflag)
@ -530,16 +534,14 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
str = fmt::format("screen.{}",universe->iworld);
screen = fopen(str.c_str(),"w");
if (screen == nullptr)
error->one(FLERR,"Cannot open screen file {}: {}",
str,utils::getsyserror());
error->one(FLERR,"Cannot open screen file {}: {}",str,utils::getsyserror());
} else if (strcmp(arg[screenflag],"none") == 0) {
screen = nullptr;
} else {
str = fmt::format("{}.{}",arg[screenflag],universe->iworld);
screen = fopen(str.c_str(),"w");
if (screen == nullptr)
error->one(FLERR,"Cannot open screen file {}: {}",
arg[screenflag],utils::getsyserror());
error->one(FLERR,"Cannot open screen file {}: {}",arg[screenflag],utils::getsyserror());
}
} else if (strcmp(arg[partscreenflag],"none") == 0) {
screen = nullptr;
@ -547,8 +549,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
str = fmt::format("{}.{}",arg[partscreenflag],universe->iworld);
screen = fopen(str.c_str(),"w");
if (screen == nullptr)
error->one(FLERR,"Cannot open screen file {}: {}",
str,utils::getsyserror());
error->one(FLERR,"Cannot open screen file {}: {}",str,utils::getsyserror());
}
if (partlogflag == 0) {
@ -556,16 +557,14 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
str = fmt::format("log.lammps.{}",universe->iworld);
logfile = fopen(str.c_str(),"w");
if (logfile == nullptr)
error->one(FLERR,"Cannot open logfile {}: {}",
str, utils::getsyserror());
error->one(FLERR,"Cannot open logfile {}: {}",str, utils::getsyserror());
} else if (strcmp(arg[logflag],"none") == 0) {
logfile = nullptr;
} else {
str = fmt::format("{}.{}",arg[logflag],universe->iworld);
logfile = fopen(str.c_str(),"w");
if (logfile == nullptr)
error->one(FLERR,"Cannot open logfile {}: {}",
str, utils::getsyserror());
error->one(FLERR,"Cannot open logfile {}: {}",str, utils::getsyserror());
}
} else if (strcmp(arg[partlogflag],"none") == 0) {
logfile = nullptr;
@ -573,15 +572,13 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
str = fmt::format("{}.{}",arg[partlogflag],universe->iworld);
logfile = fopen(str.c_str(),"w");
if (logfile == nullptr)
error->one(FLERR,"Cannot open logfile {}: {}",
str, utils::getsyserror());
error->one(FLERR,"Cannot open logfile {}: {}",str, utils::getsyserror());
}
if (strcmp(arg[inflag], "none") != 0) {
infile = fopen(arg[inflag],"r");
if (infile == nullptr)
error->one(FLERR,"Cannot open input script {}: {}",
arg[inflag], utils::getsyserror());
error->one(FLERR,"Cannot open input script {}: {}",arg[inflag], utils::getsyserror());
}
}
@ -615,12 +612,10 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) :
int mpisize;
MPI_Type_size(MPI_LMP_TAGINT,&mpisize);
if (mpisize != sizeof(tagint))
error->all(FLERR,"MPI_LMP_TAGINT and tagint in "
"lmptype.h are not compatible");
error->all(FLERR,"MPI_LMP_TAGINT and tagint in lmptype.h are not compatible");
MPI_Type_size(MPI_LMP_BIGINT,&mpisize);
if (mpisize != sizeof(bigint))
error->all(FLERR,"MPI_LMP_BIGINT and bigint in "
"lmptype.h are not compatible");
error->all(FLERR,"MPI_LMP_BIGINT and bigint in lmptype.h are not compatible");
#ifdef LAMMPS_SMALLBIG
if (sizeof(smallint) != 4 || sizeof(imageint) != 4 ||
@ -837,6 +832,8 @@ void LAMMPS::create()
void LAMMPS::post_create()
{
if (skipflag) input->one("timer timeout 0 every 1");
// default package command triggered by "-k on"
if (kokkos && kokkos->kokkos_exists) input->one("package kokkos");

View File

@ -37,38 +37,38 @@ class LAMMPS {
class Group *group; // groups of atoms
class Output *output; // thermo/dump/restart
class Timer *timer; // CPU timing info
//
class KokkosLMP *kokkos; // KOKKOS accelerator class
class AtomKokkos *atomKK; // KOKKOS version of Atom class
class MemoryKokkos *memoryKK; // KOKKOS version of Memory class
class Python *python; // Python interface
class CiteMe *citeme; // handle citation info
const char *version; // LAMMPS version string = date
int num_ver; // numeric version id derived from *version*
// that is constructed so that will be greater
// for newer versions in numeric or string
// value comparisons
//
MPI_Comm world; // MPI communicator
FILE *infile; // infile
FILE *screen; // screen output
FILE *logfile; // logfile
//
double initclock; // wall clock at instantiation
int skiprunflag; // 1 inserts timer command to skip run and minimize loops
char *suffix, *suffix2, *suffixp; // suffixes to add to input script style names
int suffix_enable; // 1 if suffixes are enabled, 0 if disabled
char *exename; // pointer to argv[0]
//
char ***packargs; // arguments for cmdline package commands
int num_package; // number of cmdline package commands
//
int clientserver; // 0 = neither, 1 = client, 2 = server
void *cslib; // client/server messaging via CSlib
MPI_Comm cscomm; // MPI comm for client+server in mpi/one mode
class KokkosLMP *kokkos; // KOKKOS accelerator class
class AtomKokkos *atomKK; // KOKKOS version of Atom class
class MemoryKokkos *memoryKK; // KOKKOS version of Memory class
class Python *python; // Python interface
class CiteMe *citeme; // handle citation info
const char *match_style(const char *style, const char *name);
static const char *installed_packages[];
static bool is_installed_pkg(const char *pkg);