From b2d1332d461c066cbab1066f5961913d48fce8ca Mon Sep 17 00:00:00 2001 From: "Steven J. Plimpton" Date: Thu, 2 Aug 2018 14:47:20 -0600 Subject: [PATCH] change proc count to color for MPI_Comm_split --- doc/src/Section_start.txt | 31 +++++++++++++++++-------------- examples/message/README | 9 ++++----- src/lammps.cpp | 26 +++++++++++--------------- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/doc/src/Section_start.txt b/doc/src/Section_start.txt index f38339661b..80f6b0ffc4 100644 --- a/doc/src/Section_start.txt +++ b/doc/src/Section_start.txt @@ -1352,24 +1352,27 @@ specified file is "none", then no log files are created. Using a "log"_log.html command in the input script will override this setting. Option -plog will override the name of the partition log files file.N. --mpi P :pre +-mpi color :pre If used, this must be the first command-line argument after the LAMMPS -executable name. It is only used when running LAMMPS in client/server -mode with the "mpi/one" mode of messaging provided by the -"message"_message.html command and the CSlib library LAMMPS links with -from the lib/message directory. See the "message"_message.html -command for more details - -In the mpi/one mode of messaging, both executables (the client and the -server) are launched by one mpirun command. P should be specified as -the number of processors (MPI tasks) the first executable is running -on (could be the client or the server code). - -This information is required so that both codes can shrink the -MPI_COMM_WORLD communicator they are part of to the subset of +executable name. It is only used when LAMMPS is launched by an mpirun +command which also launches another executable(s) (the other +executable could be LAMMPS as well) at the same time. The color is an +integer value which should be different for each executable (another +application may set this value in a different way). LAMMPS and the +other executable(s) perform an MPI_Comm_split() with their own colors +to shrink the MPI_COMM_WORLD communication to be the subset of processors they are actually running on. +Currently, this is only used in LAMMPS to perform client/server +messaging with another application. LAMMPS can act as either a client +or server (or both). + +Specifically, this refers to the "mpi/one" mode of messaging provided +by the "message"_message.html command and the CSlib library LAMMPS +links with from the lib/message directory. See the +"message"_message.html command for more details. + -nocite :pre Disable writing the log.cite file which is normally written to list diff --git a/examples/message/README b/examples/message/README index 213dbbde51..63055177a4 100644 --- a/examples/message/README +++ b/examples/message/README @@ -91,12 +91,11 @@ Mpi/one mode of messaging: Launch LAMMPS twice in a single mpirun command: -mpirun -np 2 lmp_mpi -mpi 2 -in in.message.client -v mode mpione -log log.client : -np 4 lmp_mpi -mpi 2 -in in.message.server -v mode mpione -log log.server +mpirun -np 2 lmp_mpi -mpi 0 -in in.message.client -v mode mpione -log log.client : -np 4 lmp_mpi -mpi 1 -in in.message.server -v mode mpione -log log.server The two -np values determine how many procs the client and the server run on. -A LAMMPS executable run in this manner must use the -mpi P -command-line option as their first option, where P is the number of -processors the first code in the mpirun command (client or server) is -running on. +A LAMMPS executable run in this manner must use the -mpi color +command-line option as their first option, where color is set to +one integer value for the 1st app, and another value for the 2nd app. diff --git a/src/lammps.cpp b/src/lammps.cpp index 282250c642..dec4a57186 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -86,17 +86,17 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) // check if -mpi is first arg // if so, then 2 apps were launched with one mpirun command // this means passed communicator (e.g. MPI_COMM_WORLD) is bigger than LAMMPS - // e.g. for client/server coupling with another code - // communicator needs to shrink to be just LAMMPS - // syntax: -mpi P1 means P1 procs for one app, P-P1 procs for second app - // LAMMPS could be either app, based on proc IDs + // e.g. for client/server coupling with another code + // in the future LAMMPS might leverage this in other ways + // universe communicator needs to shrink to be just LAMMPS + // syntax: -mpi color + // color = integer for this app, different than other app(s) // do the following: // perform an MPI_Comm_split() to create a new LAMMPS-only subcomm - // NOTE: assuming other app is doing the same thing, else will hang! + // NOTE: this assumes other app(s) does same thing, else will hang! // re-create universe with subcomm - // store full two-app comm in cscomm + // store full multi-app comm in cscomm // cscomm is used by CSLIB package to exchange messages w/ other app - // eventually should extend to N > 2 apps launched with one mpirun command int iarg = 1; if (narg-iarg >= 2 && (strcmp(arg[iarg],"-mpi") == 0 || @@ -104,13 +104,9 @@ LAMMPS::LAMMPS(int narg, char **arg, MPI_Comm communicator) int me,nprocs; MPI_Comm_rank(communicator,&me); MPI_Comm_size(communicator,&nprocs); - int p1 = atoi(arg[iarg+1]); - if (p1 <= 0 || p1 >= nprocs) - error->universe_all(FLERR,"Invalid command-line argument"); - int which = 0; - if (me >= p1) which = 1; + int color = atoi(arg[iarg+1]); MPI_Comm subcomm; - MPI_Comm_split(communicator,which,me,&subcomm); + MPI_Comm_split(communicator,color,me,&subcomm); cscomm = communicator; communicator = subcomm; delete universe; @@ -656,8 +652,8 @@ LAMMPS::~LAMMPS() delete [] suffix; delete [] suffix2; - // free the MPI comm created by -mpi command-line arg - // it was passed to universe as if origianl universe world + // free the MPI comm created by -mpi command-line arg processed in constructor + // it was passed to universe as if original universe world // may have been split later by partitions, universe will free the splits // free a copy of uorig here, so check in universe destructor will still work