diff --git a/examples/mdi/sequence_driver.py b/examples/mdi/sequence_driver.py index ad1633ba2c..f658214759 100644 --- a/examples/mdi/sequence_driver.py +++ b/examples/mdi/sequence_driver.py @@ -290,22 +290,42 @@ if not mdiarg: error() # 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() +#if not plugin: +# mdi.MDI_Init(mdiarg) +# world = mdi.MDI_MPI_get_world_comm() # connect to engine - mdicomm = mdi.MDI_Accept_Communicator() +# mdicomm = mdi.MDI_Accept_Communicator() - perform_tasks(world,mdicomm,None) +# perform_tasks(world,mdicomm,None) # LAMMPS engine is a plugin library # launch plugin # MDI will call back to perform_tasks() -if plugin: - mdi.MDI_Init(mdiarg) +#if plugin: +# mdi.MDI_Init(mdiarg) +# world = MPI.COMM_WORLD +# plugin_args += " -mdi \"-role ENGINE -name lammps -method LINK\"" +# mdi.MDI_Launch_plugin(plugin,plugin_args,world,perform_tasks,None) + + +# new code to auto-detect whether engine is stand-alone code or plugin library + +mdi.MDI_Init(mdiarg) +mdicomm = mdi.MDI_Get_communicator(0) + +if mdicomm == mdi.MDI_COMM_NULL: + world = mdi.MDI_MPI_get_world_comm() + mdicomm = mdi.MDI_Accept_Communicator() + if mdicomm == mdi.MDI_COMM_NULL: + error("MDI unable to connect to stand-alone engine") + perform_tasks(world,mdicomm,None) +else: world = MPI.COMM_WORLD + method = mdi.MDI_Get_method(mdicomm) + if method != mdi.MDI_PLUGIN: + error("MDI internal error for plugin engine") plugin_args += " -mdi \"-role ENGINE -name lammps -method LINK\"" mdi.MDI_Launch_plugin(plugin,plugin_args,world,perform_tasks,None) diff --git a/src/MDI/fix_mdi_aimd.cpp b/src/MDI/fix_mdi_aimd.cpp index f43b051020..055d7984b7 100644 --- a/src/MDI/fix_mdi_aimd.cpp +++ b/src/MDI/fix_mdi_aimd.cpp @@ -110,21 +110,24 @@ int FixMDIAimd::setmask() void FixMDIAimd::init() { if (mdicomm != MDI_COMM_NULL) return; - - // one-time initialization of mdicomm - // plugin = 0/1 if MDI engine is a stand-alone code vs plugin library + + // one-time auto-detect whether engine is stand-alone code or plugin library + // also initializes mdicomm + // plugin = 0/1 for engine = stand-alone code vs plugin library MDI_Get_communicator(&mdicomm,0); if (mdicomm == MDI_COMM_NULL) { plugin = 0; MDI_Accept_communicator(&mdicomm); - if (mdicomm <= 0) error->all(FLERR,"Unable to connect to MDI engine"); + if (mdicomm == MDI_COMM_NULL) + error->all(FLERR,"MDI unable to connect to stand-alone engine"); } else { plugin = 1; int method; MDI_Get_method(&method,mdicomm); - if (method != MDI_PLUGIN) error->all(FLERR,"MDI internal error"); + if (method != MDI_PLUGIN) + error->all(FLERR,"MDI internal error for plugin engine"); } }