Running many instances of lammps in serial code

Hi,

I have a C++ finite element code that runs only on a single processor (although it uses multi-threading). From this code, I am trying to perform a large number of (fairly) simple computations with LAMMPS, which is linked as a serial library (although this is not strictly relevant, the computations involve simply the calculation of the energy and forces of small atom clusters).

All the LAMMPS computations are independent from each other, and I am trying to run them in parallel, not using MPI but creating multiple threads and LAMMPS objects. I am using Intel Threading Building Blocks, but I guess the results would be the same if I used pthreads.

Each thread creates a LAMMPS object, sends the atom positions using the library.h interface, runs LAMMPS, and extracts energy and forces again using the library.h interface. After that, some clean up is performed, and the control returns to the main program.

The problem I have found is that threads seem to clash, even if each of them is using a different LAMMPS object. I have traced down the problem to the instant when two (or more) threads call simultaneously the library with the command

lammps_command(lmpobj, "run 0”);

each of them with its own (different) LAMMPS object lmpobj.

When I run the code with only one thread, everything works just fine and I am wondering if there is a fundamental reason why I can not run LAMMPS in parallel as explained, or if I need to to do additional things to for using LAMMPS in the fashion described above.

Thank for the help,

Ignacio