more debugging for plugin mode

This commit is contained in:
Steve Plimpton
2022-04-01 09:27:48 -06:00
parent 19a6eecfbb
commit 294dcc5f93
7 changed files with 104 additions and 42 deletions

View File

@ -30,7 +30,7 @@ enum{NATIVE,REAL,METAL}; // LAMMPS units which MDI supports
FixMDIAimd::FixMDIAimd(LAMMPS *lmp, int narg, char **arg) :
Fix(lmp, narg, arg)
{
if (narg != 3) error->all(FLERR, "Illegal fix mdi/aimd command");
if (narg > 4) error->all(FLERR, "Illegal fix mdi/aimd command");
scalar_flag = 1;
global_freq = 1;
@ -39,6 +39,14 @@ FixMDIAimd::FixMDIAimd(LAMMPS *lmp, int narg, char **arg) :
virial_global_flag = 1;
thermo_energy = thermo_virial = 1;
// check for plugin arg
plugin = 0;
if (narg == 4) {
if (strcmp(arg[3],"plugin") == 0) plugin = 1;
else error->all(FLERR, "Illegal fix mdi/aimd command");
}
// check requirements for LAMMPS to work with MDI as an engine
if (atom->tag_enable == 0)
@ -67,10 +75,12 @@ FixMDIAimd::FixMDIAimd(LAMMPS *lmp, int narg, char **arg) :
unit_conversions();
// connect to MDI engine
// connect to MDI engine, only if engine is stand-alone code
// MDI_Accept_communicator(&mdicomm);
// if (mdicomm <= 0) error->all(FLERR, "Unable to connect to MDI engine");
if (!plugin) {
MDI_Accept_communicator(&mdicomm);
if (mdicomm <= 0) error->all(FLERR, "Unable to connect to MDI engine");
}
nprocs = comm->nprocs;
}
@ -79,10 +89,12 @@ FixMDIAimd::FixMDIAimd(LAMMPS *lmp, int narg, char **arg) :
FixMDIAimd::~FixMDIAimd()
{
// send exit command to engine
// send exit command to engine, only if engine is stand-alone code
//int ierr = MDI_Send_command("EXIT",mdicomm);
//if (ierr) error->all(FLERR,"MDI: EXIT command");
if (!plugin) {
int ierr = MDI_Send_command("EXIT",mdicomm);
if (ierr) error->all(FLERR,"MDI: EXIT command");
}
// clean up

View File

@ -44,6 +44,8 @@ class FixMDIAimd : public Fix {
private:
int nprocs;
int plugin;
int eflag_caller;
double engine_energy;
int lmpunits;
@ -65,7 +67,6 @@ class FixMDIAimd : public Fix {
void reallocate();
void unit_conversions();
};
}

View File

@ -37,27 +37,52 @@ void MDIPlugin::command(int narg, char **arg)
if (narg < 1) error->all(FLERR,"Illegal mdi/plugin command");
char *plugin_name = arg[0];
char *plugin_args = nullptr;
plugin_command = nullptr;
printf("NARG %d\n",narg);
char *mdi_arg = nullptr;
char *infile_arg = nullptr;
char *extra_arg = nullptr;
lammps_command = nullptr;
int iarg = 1;
while (iarg < narg) {
if (strcmp(arg[iarg],"args") == 0) {
if (strcmp(arg[iarg],"mdi") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal mdi/plugin command");
plugin_args = arg[iarg+1];
mdi_arg = arg[iarg+1];
iarg += 2;
} else if (strcmp(arg[iarg],"infile") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal mdi/plugin command");
infile_arg = arg[iarg+1];
iarg += 2;
} else if (strcmp(arg[iarg],"extra") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal mdi/plugin command");
extra_arg = arg[iarg+1];
iarg += 2;
} else if (strcmp(arg[iarg],"command") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal mdi/plugin command");
plugin_command = arg[iarg+1];
int n = strlen(arg[iarg+1]) + 1;
lammps_command = new char[n];
strcpy(lammps_command,arg[iarg+1]);
iarg += 2;
} else error->all(FLERR,"Illegal mdi/plugin command");
}
// error if no command was specified
// error checks
if (!plugin_command) error->all(FLERR,"MDI/plugin must specify command");
if (!mdi_arg || !infile_arg || !lammps_command)
error->all(FLERR,"MDI/plugin must specify mdi, infile, command keywords");
// build full plugin_args string for args to plugin library
int n = strlen(mdi_arg) + strlen(infile_arg) + strlen(extra_arg) + 16;
char *plugin_args = new char[n];
strcat(plugin_args,"-mdi \"");
strcat(plugin_args,mdi_arg);
strcat(plugin_args,"\" -in ");
strcat(plugin_args,infile_arg);
if (extra_arg) {
strcat(plugin_args," ");
strcat(plugin_args,extra_arg);
}
// find FixMDIAimd instance so can reset its mdicomm
@ -72,6 +97,8 @@ void MDIPlugin::command(int narg, char **arg)
printf("ARGS %s\n",plugin_args);
MDI_Launch_plugin(plugin_name,plugin_args,world,plugin_wrapper,(void *)this);
delete [] plugin_args;
}
/* ----------------------------------------------------------------------
@ -81,25 +108,27 @@ void MDIPlugin::command(int narg, char **arg)
---------------------------------------------------------------------- */
int MDIPlugin::plugin_wrapper(void *pmpicomm, MDI_Comm mdicomm,
void *ptr)
void *vptr)
{
printf("INSIDE CALLBACK\n");
MPI_Comm mpicomm = *(MPI_Comm *) pmpicomm;
MDIPlugin *thisptr = (MDIPlugin *) ptr;
LAMMPS *lammps = thisptr->lmp;
MDIPlugin *ptr = (MDIPlugin *) vptr;
LAMMPS *lammps = ptr->lmp;
char *lammps_command = ptr->lammps_command;
// set FixMDIAimd mdicomm to this mdicomm
FixMDIAimd *aimdptr = (FixMDIAimd *) (thisptr->fixptr);
FixMDIAimd *aimdptr = (FixMDIAimd *) (ptr->fixptr);
aimdptr->mdicomm = mdicomm;
// invoke the specified LAMMPS command
// that operation will issue MDI commands to the plugin engine
printf("PRE RUN command\n");
printf("PRE RUN command: %s\n",lammps_command);
lammps->input->one(thisptr->plugin_command);
lammps->input->one(lammps_command);
delete [] lammps_command;
// send MDI exit to plugin, which unloads the plugin

View File

@ -31,7 +31,7 @@ class MDIPlugin : public Command {
void command(int, char **) override;
private:
char *plugin_command;
char *lammps_command;
class Fix *fixptr;
static int plugin_wrapper(void *, MDI_Comm, void *);

View File

@ -172,6 +172,9 @@ void *lammps_open(int argc, char **argv, MPI_Comm comm, void **ptr)
lammps_mpi_init();
if (ptr) ptr_argument_warning();
printf("LAMMPS instantiate argc %d argv[1] %s argv[2] %s\n",
argc,argv[1],argv[2]);
#ifdef LAMMPS_EXCEPTIONS
try
{
@ -183,7 +186,9 @@ void *lammps_open(int argc, char **argv, MPI_Comm comm, void **ptr)
if (ptr) *ptr = nullptr;
}
#else
printf("PRE-INSTANTIATE\n");
lmp = new LAMMPS(argc, argv, comm);
printf("POST-INSTANTIATE %p\n",lmp);
if (ptr) *ptr = (void *) lmp;
#endif
return (void *) lmp;