OpenMP multi thread with Coupled Fortran based code

Hello Sir,

I am using a LAMMPS as a library in Fortran based code. I use these command to compile my Fortran based code using LAMMPS as a library.

mpif90 -c lammps.f90
mpif90 -c Hybrid_Code.f90 -fopenmp
mpif90 LAMMPS.o Hybrid_Code.o liblammps.a -lmpi _cxx -lstdc++ -lm -ldl -fopenmp
env OMP_NUM_THREADS=16 ./a.out P in.lammpps -fopenmp

But the multithreading is not working. I am interested in multi-threading because my Fortran based code is OpenMP parallel. How i can modify the compiling commands to account for parallel programming?

Besides this, i also enabled omp package and used pair_style lj/cut/omp, fix 1 all nve/omp. But i did not see other commands of omp related to my code. So this is no use for me.

Best regards

First of all, your LAMMPS library has to be compiled with OpenMP enabled (not just the OPENMP package installed). How you compile your code and the LAMMPS Fortran module is irrelevant. This information is not present, so it is impossible to say, whether this is sufficient.

Furthermore, it crucially depends on what commands you pass to LAMMPS and how whether this will choose the OpenMP capable code paths. It does things a bit different than most OpenMP based codes.
This information is also missing, so it is impossible to provide any advice on how to enable multi-threading.

Finally, there is no information and specifically no LAMMPS output information providing evidence that OpenMP multi-threading is properly enabled and that calculations are performed that do support multi-threading.

Please note that multi-threading in LAMMPS is only the second best option to parallelize a calculation. MPI parallelization is far more effective (by construction) and the OpenMP support has been optimized for a small number of threads (2-8).