I'm trying to make a parallel C++ code that runs parallel instances of LAMMPS, but I'm running into some issues. Here's a very simplified example of my code:
//////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <sstream>
#include "mpi.h"
// LAMMPS files
#include "lammps.h"
#include "input.h"
#include "atom.h"
#include "library.h"
using namespace std;
// LAMMPS namespace and pointers
using namespace LAMMPS_NS;
char *args1[] = {
(char *) "lmp",
(char *) "-log",
(char*) "none",
0};
LAMMPS *lmp;
int main(int argc, char **argv)
{
// Start MPI
MPI_Init(&argc,&argv);
// Create instance of LAMMPS
lmp = new LAMMPS(3,args1,MPI_COMM_WORLD);
// Finalize MPI
MPI_Finalize();
}
//////////////////////////////////////////////////////////////////////////////
This is simply the standard way of calling LAMMPS within C++.
I successfully compile with:
mpiCC test.cpp -o test /path/to/liblammps.so
I successfully execute with:
mpirun -np 1 test
I cannot, however, successfully execute with:
mpirun -np 2 test
It seems whenever I use more than one process, the program freezes and the other processes never actually start an instance of LAMMPS.
Can I use the same dynamic variable (lmp) for all processes, like I am doing in this example? How can I run multiple instances in parallel?
Thanks for your time.