debugging plugin mode
This commit is contained in:
@ -99,7 +99,7 @@ the info is copied here:
|
||||
|
||||
Run with TCP: 1 proc each
|
||||
|
||||
% python3 series_driver.py -mdi "-role DRIVER -name aimd -method TCP -port 8021"
|
||||
% python3 series_driver.py -mdi "-role DRIVER -name series -method TCP -port 8021"
|
||||
|
||||
% lmp_mpi -mdi "-role ENGINE -name LAMMPS -method TCP -port 8021 -hostname localhost" -log log.series -in in.series
|
||||
|
||||
@ -107,7 +107,7 @@ Run with TCP: 1 proc each
|
||||
|
||||
Run with TCP: 2 proc + 4 procs
|
||||
|
||||
% mpirun -np 2 python3 series_driver.py -mdi "-role DRIVER -name aimd -method TCP -port 8021"
|
||||
% mpirun -np 2 python3 series_driver.py -mdi "-role DRIVER -name series -method TCP -port 8021"
|
||||
|
||||
% mpirun -np 4 lmp_mpi -mdi "-role ENGINE -name LAMMPS -method TCP -port 8021 -hostname localhost" -log log.series -in in.series
|
||||
|
||||
@ -115,12 +115,19 @@ Run with TCP: 2 proc + 4 procs
|
||||
|
||||
Run with MPI: 1 proc each
|
||||
|
||||
% mpirun -np 1 python3 series_driver.py -mdi "-role DRIVER -name aimd -method MPI" : -np 1 lmp_mpi -mdi "-role ENGINE -name LAMMPS -method MPI" -log log.series -in in.series
|
||||
% mpirun -np 1 python3 series_driver.py -mdi "-role DRIVER -name series -method MPI" : -np 1 lmp_mpi -mdi "-role ENGINE -name LAMMPS -method MPI" -log log.series -in in.series
|
||||
|
||||
---
|
||||
|
||||
Run with MPI: 2 procs + 3 procs
|
||||
|
||||
% mpirun -np 2 python3 series_driver.py -mdi "-role DRIVER -name aimd -method MPI" : -np 3 lmp_mpi -mdi "-role ENGINE -name LAMMPS -method MPI" -log log.series -in in.series
|
||||
% mpirun -np 2 python3 series_driver.py -mdi "-role DRIVER -name series -method MPI" : -np 3 lmp_mpi -mdi "-role ENGINE -name LAMMPS -method MPI" -log log.series -in in.series
|
||||
|
||||
---
|
||||
|
||||
Run in plugin mode: 1 proc
|
||||
|
||||
% python3 series_driver.py -plugin lammps -mdi "-role DRIVER -name series -method LINK -plugin_path /home/sjplimp/lammps/git/src" -plugin_args "-log log.series -in in.series"
|
||||
|
||||
|
||||
mpiexec -n 1 python3 plugin_driver.py --plugin_name "lammps" --mdi "-role DRIVER -name driver -method LINK -plugin_path /home/sjplimp/lammps/git/src" --plugin_command_line "foo -in in.series"
|
||||
|
||||
@ -1,10 +1,20 @@
|
||||
# MDI driver to perform a series of independent calculations
|
||||
# using LAMMPS as an engine
|
||||
# using LAMMPS as a standalone engine
|
||||
|
||||
# Syntax: python3 series_driver.py switch arg switch arg ...
|
||||
# possible switches:
|
||||
# -mdi "-role DRIVER ..."
|
||||
# required switch
|
||||
# example for stand-alone mode:
|
||||
# -mdi "-role DRIVER -name sequence -method TCP -port 8021"
|
||||
# example for plugin mode:
|
||||
# -mdi "-role DRIVER -name sequemce -method LINK
|
||||
# -plugin_path /home/sjplimp/lammps/src/"
|
||||
# -plugin name
|
||||
# name of plugin library, only when using plugin mode
|
||||
# -plugin_args arglist
|
||||
# args to add when launching plugin library, only when using plugin mode
|
||||
# enclose arglist in quotes if multiple words
|
||||
# -n 10
|
||||
# number of calculations to perform, default = 1
|
||||
# -mode eval/run/min
|
||||
@ -15,7 +25,7 @@
|
||||
# -rho 0.75 0.1
|
||||
# reduced density and random variation thereof, default = 0.75 0.1
|
||||
# -delta 0.1
|
||||
# randomly perturb atoms initially by this distance, default 0.0
|
||||
# randomly perturb atoms initially by this distance, default 0.1
|
||||
# -nsteps 100
|
||||
# number of timesteps in dynamics runs, default = 100
|
||||
# -temp 1.0
|
||||
@ -36,102 +46,17 @@ def error(txt=None):
|
||||
if txt: raise Exception(txt)
|
||||
raise Exception("Syntax: python3 series_driver.py switch arg switch arg ...")
|
||||
|
||||
# send a LAMMPS input script command to MDI engine
|
||||
# loop over all the tasks to exchange MDI Sends/Receives with the engine
|
||||
# for standalone mode, this is called by main program below
|
||||
# for plugin mode, this is a callback function invoked by MDI
|
||||
|
||||
def send_command(cmd):
|
||||
mdi.MDI_Send_Command("NBYTES",mdicomm)
|
||||
mdi.MDI_Send(len(cmd),1,mdi.MDI_INT,mdicomm)
|
||||
mdi.MDI_Send_Command("COMMAND",mdicomm)
|
||||
mdi.MDI_Send(cmd,len(cmd)+1,mdi.MDI_CHAR,mdicomm)
|
||||
def perform_tasks(world,mdicomm,dummy):
|
||||
|
||||
# parse command-line args
|
||||
print("PT start",world,mdicomm,dummy)
|
||||
|
||||
args = sys.argv[1:]
|
||||
narg = len(args)
|
||||
|
||||
mdiarg = 0
|
||||
ncalc = 1
|
||||
mode = "eval"
|
||||
nx = ny = nz = 2
|
||||
rho = 0.75
|
||||
rhodelta = 0.1
|
||||
delta = 0.1
|
||||
nsteps = 100
|
||||
tinitial = 1.0
|
||||
tol = 0.001
|
||||
seed = 12345
|
||||
|
||||
iarg = 0
|
||||
while iarg < narg:
|
||||
if args[iarg] == "-mdi":
|
||||
if iarg+2 > narg: error()
|
||||
mdiarg = iarg + 1
|
||||
iarg += 2
|
||||
elif args[iarg] == "-n":
|
||||
if iarg+2 > narg: error()
|
||||
ncalc = int(args[iarg+1])
|
||||
iarg += 2
|
||||
elif args[iarg] == "-mode":
|
||||
if iarg+2 > narg: error()
|
||||
mode = args[iarg+1]
|
||||
if mode != "eval" and mode != "run" and mode != "min": error()
|
||||
iarg += 2
|
||||
elif args[iarg] == "-size":
|
||||
if iarg+4 > narg: error()
|
||||
nx = int(args[iarg+1])
|
||||
ny = int(args[iarg+2])
|
||||
nz = int(args[iarg+3])
|
||||
if nx <= 0 or ny <= 0 or nz <= 0: error()
|
||||
iarg += 4
|
||||
elif args[iarg] == "-rho":
|
||||
if iarg+3 > narg: error()
|
||||
rho = float(args[iarg+1])
|
||||
rhodelta = float(args[iarg+2])
|
||||
if rho-rhodelta <= 0.0: error()
|
||||
iarg += 3
|
||||
elif args[iarg] == "-delta":
|
||||
if iarg+2 > narg: error()
|
||||
delta = float(args[iarg+1])
|
||||
if delta < 0.0: error()
|
||||
iarg += 2
|
||||
elif args[iarg] == "-nsteps":
|
||||
if iarg+2 > narg: error()
|
||||
nsteps = int(args[iarg+1])
|
||||
if nsteps < 0: error()
|
||||
iarg += 2
|
||||
elif args[iarg] == "-temp":
|
||||
if iarg+2 > narg: error()
|
||||
tinitial = float(args[iarg+1])
|
||||
if tinitial < 0.0: error()
|
||||
iarg += 2
|
||||
elif args[iarg] == "-tol":
|
||||
if iarg+2 > narg: error()
|
||||
tol = float(args[iarg+1])
|
||||
if tol < 0.0: error()
|
||||
iarg += 2
|
||||
elif args[iarg] == "-seed":
|
||||
if iarg+2 > narg: error()
|
||||
seed = int(args[iarg+1])
|
||||
if seed <= 0: error()
|
||||
iarg += 2
|
||||
else: error()
|
||||
|
||||
if not mdiarg: error()
|
||||
|
||||
# initialize MDI Library
|
||||
|
||||
mdi.MDI_Init(args[mdiarg])
|
||||
|
||||
# MPI communicator for just the driver
|
||||
|
||||
world = mdi.MDI_MPI_get_world_comm()
|
||||
me = world.Get_rank()
|
||||
nprocs = world.Get_size()
|
||||
|
||||
# connect to engine
|
||||
|
||||
mdicomm = mdi.MDI_Accept_Communicator()
|
||||
|
||||
# allocate vectors for per-atom types, coords, vels, forces
|
||||
|
||||
natoms = nx * ny * nz
|
||||
@ -163,8 +88,10 @@ for icalc in range(ncalc):
|
||||
# send simulation box to engine
|
||||
|
||||
vec = [xhi-xlo,0.0,0.0] + [0.0,yhi-ylo,0.0] + [0.0,0.0,zhi-zlo]
|
||||
print("PRE-CELL",mdicomm)
|
||||
mdi.MDI_Send_command(">CELL",mdicomm)
|
||||
mdi.MDI_Send(vec,9,mdi.MDI_DOUBLE,mdicomm)
|
||||
print("POST-CELL")
|
||||
|
||||
# create atoms on perfect lattice
|
||||
|
||||
@ -226,8 +153,10 @@ for icalc in range(ncalc):
|
||||
|
||||
# request potential energy
|
||||
|
||||
print("PRE-PE")
|
||||
|
||||
mdi.MDI_Send_command("<PE",mdicomm)
|
||||
print("POST-PE")
|
||||
pe = mdi.MDI_Recv(1,mdi.MDI_DOUBLE,mdicomm)
|
||||
pe = world.bcast(pe,root=0)
|
||||
|
||||
@ -266,5 +195,128 @@ for icalc in range(ncalc):
|
||||
if me == 0: print(line)
|
||||
|
||||
# send EXIT command to engine
|
||||
# in plugin mode, removes the plugin library
|
||||
|
||||
mdi.MDI_Send_command("EXIT",mdicomm)
|
||||
|
||||
# return needed for plugin callback mode
|
||||
|
||||
return 0
|
||||
|
||||
# ------------------------
|
||||
# main program
|
||||
# ------------------------
|
||||
|
||||
args = sys.argv[1:]
|
||||
narg = len(args)
|
||||
|
||||
# defaults for command-line args
|
||||
|
||||
mdiarg = ""
|
||||
plugin = ""
|
||||
plugin_args = ""
|
||||
|
||||
ncalc = 1
|
||||
mode = "eval"
|
||||
nx = ny = nz = 2
|
||||
rho = 0.75
|
||||
rhodelta = 0.1
|
||||
delta = 0.1
|
||||
nsteps = 100
|
||||
tinitial = 1.0
|
||||
tol = 0.001
|
||||
seed = 12345
|
||||
|
||||
# parse command-line args
|
||||
|
||||
iarg = 0
|
||||
while iarg < narg:
|
||||
if args[iarg] == "-mdi":
|
||||
if iarg+2 > narg: error()
|
||||
mdiarg = args[iarg+1]
|
||||
iarg += 2
|
||||
elif args[iarg] == "-plugin":
|
||||
if iarg+2 > narg: error()
|
||||
plugin = args[iarg+1]
|
||||
iarg += 2
|
||||
elif args[iarg] == "-plugin_args":
|
||||
if iarg+2 > narg: error()
|
||||
plugin_args = args[iarg+1]
|
||||
iarg += 2
|
||||
elif args[iarg] == "-n":
|
||||
if iarg+2 > narg: error()
|
||||
ncalc = int(args[iarg+1])
|
||||
iarg += 2
|
||||
elif args[iarg] == "-mode":
|
||||
if iarg+2 > narg: error()
|
||||
mode = args[iarg+1]
|
||||
if mode != "eval" and mode != "run" and mode != "min": error()
|
||||
iarg += 2
|
||||
elif args[iarg] == "-size":
|
||||
if iarg+4 > narg: error()
|
||||
nx = int(args[iarg+1])
|
||||
ny = int(args[iarg+2])
|
||||
nz = int(args[iarg+3])
|
||||
if nx <= 0 or ny <= 0 or nz <= 0: error()
|
||||
iarg += 4
|
||||
elif args[iarg] == "-rho":
|
||||
if iarg+3 > narg: error()
|
||||
rho = float(args[iarg+1])
|
||||
rhodelta = float(args[iarg+2])
|
||||
if rho-rhodelta <= 0.0: error()
|
||||
iarg += 3
|
||||
elif args[iarg] == "-delta":
|
||||
if iarg+2 > narg: error()
|
||||
delta = float(args[iarg+1])
|
||||
if delta < 0.0: error()
|
||||
iarg += 2
|
||||
elif args[iarg] == "-nsteps":
|
||||
if iarg+2 > narg: error()
|
||||
nsteps = int(args[iarg+1])
|
||||
if nsteps < 0: error()
|
||||
iarg += 2
|
||||
elif args[iarg] == "-temp":
|
||||
if iarg+2 > narg: error()
|
||||
tinitial = float(args[iarg+1])
|
||||
if tinitial < 0.0: error()
|
||||
iarg += 2
|
||||
elif args[iarg] == "-tol":
|
||||
if iarg+2 > narg: error()
|
||||
tol = float(args[iarg+1])
|
||||
if tol < 0.0: error()
|
||||
iarg += 2
|
||||
elif args[iarg] == "-seed":
|
||||
if iarg+2 > narg: error()
|
||||
seed = int(args[iarg+1])
|
||||
if seed <= 0: error()
|
||||
iarg += 2
|
||||
else: error()
|
||||
|
||||
if not mdiarg: error()
|
||||
|
||||
# LAMMPS engine is a stand-alone code
|
||||
# world = MPI communicator for just this driver
|
||||
# invoke perform_tasks() directly
|
||||
|
||||
if not plugin:
|
||||
mdi.MDI_Init(mdiarg)
|
||||
world = mdi.MDI_MPI_get_world_comm()
|
||||
|
||||
# connect to engine
|
||||
|
||||
mdicomm = mdi.MDI_Accept_Communicator()
|
||||
|
||||
perform_tasks(world,mdicomm,None)
|
||||
|
||||
# LAMMPS engine is a plugin library
|
||||
# launch plugin
|
||||
# MDI will call back to perform_tasks()
|
||||
|
||||
print("PRE PLUGIN");
|
||||
|
||||
if plugin:
|
||||
mdi.MDI_Init(mdiarg)
|
||||
world = MPI.COMM_WORLD
|
||||
plugin_args += " -mdi \"-role ENGINE -name lammps -method LINK\""
|
||||
print("PRE LAUNCH",plugin_args)
|
||||
mdi.MDI_Launch_plugin(plugin,plugin_args,world,perform_tasks,None)
|
||||
|
||||
@ -34,7 +34,7 @@ make lib-meam args="-m ifort" # build MEAM lib with custom Makefile.ifort (usi
|
||||
|
||||
# settings
|
||||
|
||||
version = "1.2.9"
|
||||
version = "1.3.0"
|
||||
url = "https://github.com/MolSSI-MDI/MDI_Library/archive/v%s.tar.gz" % version
|
||||
|
||||
# known checksums for different MDI versions. used to validate the download.
|
||||
|
||||
@ -54,6 +54,8 @@ command-line argument, which must be provided by the MDI driver.
|
||||
|
||||
int MDI_Plugin_init_lammps()
|
||||
{
|
||||
printf("LMP PLUGIN init\n");
|
||||
|
||||
// initialize MDI
|
||||
|
||||
int mdi_argc;
|
||||
@ -69,6 +71,8 @@ int MDI_Plugin_init_lammps()
|
||||
|
||||
// find the -in argument
|
||||
|
||||
printf("LMP PLUGIN init %d %s %s\n",mdi_argc,mdi_argv[0],mdi_argv[1]);
|
||||
|
||||
int iarg = 0;
|
||||
char *filename;
|
||||
bool found_filename = false;
|
||||
@ -93,6 +97,8 @@ int MDI_Plugin_init_lammps()
|
||||
|
||||
// create and run a LAMMPS instance
|
||||
|
||||
printf("LMP PLUGIN init %d %s %s\n",mdi_argc,mdi_argv[0],mdi_argv[1]);
|
||||
|
||||
void *lmp = nullptr;
|
||||
if (lammps_config_has_mpi_support() > 0)
|
||||
lmp = lammps_open(mdi_argc, mdi_argv, mpi_world_comm, nullptr);
|
||||
|
||||
@ -174,6 +174,8 @@ void MDIEngine::mdi_engine(int narg, char **arg)
|
||||
MDI_Accept_communicator(&mdicomm);
|
||||
if (mdicomm <= 0) error->all(FLERR,"Unable to connect to MDI driver");
|
||||
|
||||
printf("ENG post accept MDI comm\n");
|
||||
|
||||
// endless engine loop, responding to driver commands
|
||||
|
||||
mode = DEFAULT;
|
||||
@ -235,6 +237,8 @@ void MDIEngine::engine_node(const char *node)
|
||||
{
|
||||
int ierr;
|
||||
|
||||
printf("ENG ENODE %s\n",node);
|
||||
|
||||
// do not process commands if engine and driver request are not the same
|
||||
|
||||
strncpy(node_engine,node,MDI_COMMAND_LENGTH);
|
||||
@ -249,9 +253,13 @@ void MDIEngine::engine_node(const char *node)
|
||||
// read the next command from the driver
|
||||
// all procs call this, but only proc 0 receives the command
|
||||
|
||||
printf("ENG PRE-RECV %d\n",mdicomm);
|
||||
|
||||
ierr = MDI_Recv_command(mdicmd,mdicomm);
|
||||
if (ierr) error->all(FLERR,"MDI: Unable to receive command from driver");
|
||||
|
||||
printf("ENG POST-RECV %s\n",mdicmd);
|
||||
|
||||
// broadcast command to the other MPI tasks
|
||||
|
||||
MPI_Bcast(mdicmd,MDI_COMMAND_LENGTH,MPI_CHAR,0,world);
|
||||
|
||||
Reference in New Issue
Block a user