Add support for MDI Plugin System
This commit is contained in:
@ -31,6 +31,7 @@
|
||||
#include "group.h"
|
||||
#include "info.h"
|
||||
#include "input.h"
|
||||
#include "mdi_interface.h"
|
||||
#include "memory.h"
|
||||
#include "modify.h"
|
||||
#include "molecule.h"
|
||||
@ -4975,6 +4976,56 @@ int lammps_get_last_error_message(void *handle, char *buffer, int buf_size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// MDI functions
|
||||
// ----------------------------------------------------------------------
|
||||
int MDI_Plugin_init_lammps() {
|
||||
// initialize MDI
|
||||
int mdi_argc;
|
||||
char** mdi_argv;
|
||||
if ( MDI_Plugin_get_argc(&mdi_argc) )
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
if ( MDI_Plugin_get_argv(&mdi_argv) )
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
if ( MDI_Init(&mdi_argc, &mdi_argv) )
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
|
||||
// get the MPI intra-communicator for this code
|
||||
MPI_Comm mpi_world_comm = MPI_COMM_WORLD;
|
||||
if ( MDI_MPI_get_world_comm(&mpi_world_comm) )
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
|
||||
// find the -in argument
|
||||
int iarg = 0;
|
||||
char *filename;
|
||||
bool found_filename = false;
|
||||
while( iarg < mdi_argc && !found_filename ) {
|
||||
if (strcmp(mdi_argv[iarg],"-in") == 0 ||
|
||||
strcmp(mdi_argv[iarg],"-i") == 0) {
|
||||
if (iarg+2 > mdi_argc)
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
filename = mdi_argv[iarg+1];
|
||||
found_filename = true;
|
||||
|
||||
// remove -in argument from the command list
|
||||
mdi_argc -= 2;
|
||||
for (int jarg=iarg; jarg < mdi_argc; jarg++) {
|
||||
mdi_argv[jarg] = mdi_argv[jarg+2];
|
||||
}
|
||||
}
|
||||
iarg++;
|
||||
}
|
||||
if (!found_filename)
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
|
||||
// create and run a LAMMPS instance
|
||||
LAMMPS *lmp = (LAMMPS*) lammps_open(mdi_argc, mdi_argv, mpi_world_comm, NULL);
|
||||
lammps_file(lmp, filename);
|
||||
lammps_close(lmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
// fill-column: 72
|
||||
// End:
|
||||
|
||||
@ -243,6 +243,12 @@ void lammps_force_timeout(void *handle);
|
||||
int lammps_has_error(void *handle);
|
||||
int lammps_get_last_error_message(void *handle, char *buffer, int buf_size);
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* MDI functions
|
||||
* ---------------------------------------------------------------------- */
|
||||
int MDI_Plugin_init_lammps();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -29,6 +29,8 @@
|
||||
int MDI_Init(int* argc, char ***argv) {return 0;};
|
||||
int MDI_Initialized(int* flag) {return 0;};
|
||||
int MDI_MPI_get_world_comm(void* world_comm) {return 0;};
|
||||
int MDI_Plugin_get_argc(int* argc) {return 0;};
|
||||
int MDI_Plugin_get_argv(char*** argv) {return 0;};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user