Call two instances of liggghts from C++

Submitted by Ming on Thu, 01/27/2022 - 18:35

Hi.

Following the online documentation, I have been able to create a liggghts instance from C++ and it can run parallel without any issue. But if I delete the current instance and create a new one, a warning will be encountered such as "WARNING! Style collision detected! Duplicate entry (gran, 68) in style table". I guess it may be due to some MPI issues with which I am not familiar. My main c++ code is shown as below:
LAMMPS_NS::LAMMPS *lmp = NULL;
//custom argument vector for LAMMPS library
const char *lmpargv[] = {"liblmp_auto", "-log", "none"};
int lmpargc = sizeof(lmpargv)/sizeof(const char *);
// explicitly initialize MPI
MPI_Init(&argc, &argv);

// create LAMMPS instance
lmp = new LAMMPS_NS::LAMMPS(lmpargc, (char **)lmpargv, MPI_COMM_WORLD);
// output numerical version string
std::cout << "LAMMPS init clock: " << lmp->initclock << std::endl;
lmp->input->file(argv[1]);
lmp->input->one("write_restart h0.equil");
lmp->input->one("run 100");
std::cout << lmp->update->ntimestep << std::endl;
delete lmp;
//
MPI_Barrier(MPI_COMM_WORLD);
// create another LAMMPS instance
lmp = NULL;
lmp = new LAMMPS_NS::LAMMPS(lmpargc, (char **)lmpargv, MPI_COMM_WORLD);
// lmp = new LAMMPS_NS::LAMMPS(0, NULL, MPI_COMM_WORLD);
lmp->input->file(argv[1]);
lmp->input->one("run 100");

Please let me know if you have any suggestions to avoid the warning or make the code run in the right way. Thanks.

PS: I tried this using the latest LAMMPS. This warning does not appear.