From 371b1a80e3e603607df19e783aa0c003af18b070 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 19 Nov 2020 18:58:21 -0500 Subject: [PATCH] add support for '-in none' for multi-partition runs from the library interface --- doc/src/Run_options.rst | 19 +++++++++++-------- src/input.cpp | 7 +++++++ src/lammps.cpp | 13 ++++++++----- unittest/c-library/test_library_mpi.cpp | 5 +---- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/doc/src/Run_options.rst b/doc/src/Run_options.rst index f5435ec3a9..9c269e552f 100644 --- a/doc/src/Run_options.rst +++ b/doc/src/Run_options.rst @@ -62,15 +62,18 @@ used. **-in file** -Specify a file to use as an input script. This is an optional switch -when running LAMMPS in one-partition mode. If it is not specified, -LAMMPS reads its script from standard input, typically from a script -via I/O redirection; e.g. lmp_linux < in.run. I/O redirection should -also work in parallel, but if it does not (in the unlikely case that -an MPI implementation does not support it), then use the -in flag. +Specify a file to use as an input script. This is an optional but +recommended switch when running LAMMPS in one-partition mode. If it +is not specified, LAMMPS reads its script from standard input, typically +from a script via I/O redirection; e.g. lmp_linux < in.run. +With many MPI implementations I/O redirection also works in parallel, +but using the -in flag will always work. + Note that this is a required switch when running LAMMPS in multi-partition mode, since multiple processors cannot all read from -stdin. +stdin concurrently. The file name may be "none" for starting +multi-partition calculations without reading an initial input file +from the library interface. ---------- @@ -296,7 +299,7 @@ command-line option. **-pscreen file** Specify the base name for the partition screen file, so partition N -writes screen information to file.N. If file is none, then no +writes screen information to file.N. If file is "none", then no partition screen files are created. This overrides the filename specified in the -screen command-line option. This option is useful when working with large numbers of partitions, allowing the partition diff --git a/src/input.cpp b/src/input.cpp index c907a16c9d..abdc3775ce 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -189,8 +189,15 @@ void Input::file() // if line ends in continuation char '&', concatenate next line if (me == 0) { + m = 0; while (1) { + + if (infile == nullptr) { + n = 0; + break; + } + if (maxline-m < 2) reallocate(line,maxline,0); // end of file reached, so break diff --git a/src/lammps.cpp b/src/lammps.cpp index ff0df97105..102d2f18cf 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -456,6 +456,7 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : if (universe->me == 0) { if (inflag == 0) infile = stdin; + else if (strcmp(arg[inflag], "none") == 0) infile = stdin; else infile = fopen(arg[inflag],"r"); if (infile == nullptr) error->one(FLERR,fmt::format("Cannot open input script {}: {}", @@ -530,10 +531,12 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) : str, utils::getsyserror())); } - infile = fopen(arg[inflag],"r"); - if (infile == nullptr) - error->one(FLERR,fmt::format("Cannot open input script {}: {}", - arg[inflag], utils::getsyserror())); + if (strcmp(arg[inflag], "none") != 0) { + infile = fopen(arg[inflag],"r"); + if (infile == nullptr) + error->one(FLERR,fmt::format("Cannot open input script {}: {}", + arg[inflag], utils::getsyserror())); + } } // screen and logfile messages for universe and world @@ -1103,7 +1106,7 @@ void _noopt LAMMPS::help() "List of command line options supported by this LAMMPS executable:\n\n" "-echo none/screen/log/both : echoing of input script (-e)\n" "-help : print this help message (-h)\n" - "-in filename : read input from file, not stdin (-i)\n" + "-in none/filename : read input from file or stdin (default) (-i)\n" "-kokkos on/off ... : turn KOKKOS mode on or off (-k)\n" "-log none/filename : where to send log output (-l)\n" "-mpicolor color : which exe in a multi-exe mpirun cmd (-m)\n" diff --git a/unittest/c-library/test_library_mpi.cpp b/unittest/c-library/test_library_mpi.cpp index 029af72c84..7936ee45ad 100644 --- a/unittest/c-library/test_library_mpi.cpp +++ b/unittest/c-library/test_library_mpi.cpp @@ -156,11 +156,9 @@ TEST(MPI, multi_partition) lammps_mpi_init(); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &me); - fp = fopen("in.mp_dummy", "w"); - fclose(fp); const char *args[] = {"LAMMPS_test", "-log", "none", "-partition", "2x2", - "-echo", "screen", "-nocite", "-in", "in.mp_dummy"}; + "-echo", "screen", "-nocite", "-in", "none"}; char **argv = (char **)args; int argc = sizeof(args) / sizeof(char *); void *lmp = lammps_open(argc, argv, MPI_COMM_WORLD, nullptr); @@ -184,7 +182,6 @@ TEST(MPI, multi_partition) } lammps_close(lmp); - unlink("in.mp_dummy"); }; class MPITest : public ::testing::Test {