Dear all,
I try to compile Lammps with the python module mode in the configuration of a virtual environment. But Lammps (lmp_mpi) does not find the liblammps_mpi.so. I do not know how to solve the problem.
I use the Lammps version 29Oct2020 with openmpi-4.0.2 and ubuntu 16.04. I had to add “std=c++11” in the makefile in folder MINE. Lammps/openmpi compiled with make and the packages KSPACE MANYBODY MOLECULE RIGD works.
As explained in the Manual 29Oct2020 :
1/ I create the virtual environment with “python3 -m venv $HOME/myenv”
2/ The virtual environment is activated with “source $HOME/myenv/bin/activate” :
which python :
/home/pierre/myenv/bin/python
in ~/myenv/bin:
ls -l
-rw-rw-r-- 1 pierre pierre 1894 Sep 4 14:21 activate
-rw-rw-r-- 1 pierre pierre 843 Sep 4 14:21 activate.csh
-rw-rw-r-- 1 pierre pierre 1983 Sep 4 14:21 activate.fish
-rw-rw-r-- 1 pierre pierre 8834 Sep 4 14:21 Activate.ps1
-rwxrwxr-x 1 pierre pierre 235 Sep 4 14:21 pip
-rwxrwxr-x 1 pierre pierre 235 Sep 4 14:21 pip3
-rwxrwxr-x 1 pierre pierre 235 Sep 4 14:21 pip3.9
lrwxrwxrwx 1 pierre pierre 7 Sep 4 14:21 python → python3
lrwxrwxrwx 1 pierre pierre 35 Sep 4 14:21 python3 → /home/pierre/miniconda3/bin/python3
lrwxrwxrwx 1 pierre pierre 7 Sep 4 14:21 python3.9 → python3
3/ In the folder $HOME/lammps/src, the 4 packages are installed with “make yes-KSPACE yes-….”
4/ I compile lammps in share mode with “make -j 4 mode=shared mpi_2” (mpi_2 is the modified makefile in the directory MINE).
As usual I get two warnings :
mpicxx -g -O3 -std=c++11 -fPIC -DLAMMPS_GZIP -DLAMMPS_MEMALIGN=64 -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX=1 -c …/variable.cpp
…/variable.cpp: In member function ‘int LAMMPS_NS::Variable::next(int, char**)’:
…/variable.cpp:712:27: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
fread(buf,1,64,fp);
^
mpicxx -g -O3 -std=c++11 -fPIC -DLAMMPS_GZIP -DLAMMPS_MEMALIGN=64 -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX=1 -c …/read_restart.cpp
…/read_restart.cpp: In member function ‘void LAMMPS_NS::ReadRestart::check_eof_magic()’:
…/read_restart.cpp:1198:33: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
fread(str,sizeof(char),n,fp);
^
At the end of the compilation:
mpicxx -g -O3 -std=c++11 -fPIC -DLAMMPS_GZIP -DLAMMPS_MEMALIGN=64 -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX=1 -c …/variable.cpp
size …/lmp_mpi_2
text data bss dec hex filename
2734 712 8 3454 d7e …/lmp_mpi_2
make[1] : on quitte le répertoire « /home/pierre/lammps-29Oct20/src/Obj_shared_mpi_2 »
=> (myenv) (base) pierre@mrsm2p2itc-s30:~/lammps-29Oct20/src$ ls -l li*
-rw-rw-r-- 1 pierre pierre 177235534 Sep 1 16:43 liblammps_mpi_2.a
-rwxrwxr-x 1 pierre pierre 63762208 Sep 4 14:28 liblammps_mpi_2.so
-rw-rw-r-- 1 pierre pierre 131869982 Oct 8 2021 liblammps_serial_2.a
lrwxrwxrwx 1 pierre pierre 18 Sep 4 14:28 liblammps.so -> liblammps_mpi_2.so
5/ I install python in module mode with “make install-python”:
Installing LAMMPS Python module version 29Oct2020 into site-packages folder
running install
running build
running build_py
creating build
creating build/lib
copying lammps.py → build/lib
running install_lib
copying build/lib/lammps.py → /home/pierre/myenv/lib/python3.9/site-packages
byte-compiling /home/pierre/myenv/lib/python3.9/site-packages/lammps.py to lammps.cpython-39.pyc
running install_data
copying /home/pierre/lammps-29Oct20/src/liblammps.so → /home/pierre/myenv/lib/python3.9/site-packages
running install_egg_info
Writing /home/pierre/myenv/lib/python3.9/site-packages/lammps-29Oct2020-py3.9.egg-info
==============================================================================> At this stage, all seem all right. liblammps.so is copied in $HOME/myenv/lib/python3.9/site-packages and $HOME/myenv/lib64/python3.9/site-packages.
=> However, liblammps_mpi_2.so is copied in $HOME/myenv/lib/python3.9/site-packages but not in $HOME/myenv/lib64/python3.9/site-packages. <=
=> When I use Lammps with mpirun -np 2 lmp_mpi_2 -in TEST_LAMMPS_MPI_PYTHON.in, I get :
lmp_mpi_2: error while loading shared libraries: liblammps_mpi_2.so: cannot open shared object file: No such file or directory
Primary job terminated normally, but 1 process returned
a non-zero exit code. Per user-direction, the job has been aborted.
lmp_mpi_2: error while loading shared libraries: liblammps_mpi_2.so: cannot open shared object file: No such file or directory
=> If I create a Lammps instance :
import lammps
lmp = lammps.lammps()
LAMMPS (29 Oct 2020)
lmp = lammps.lammps(name=‘mpi_2’)
Traceback (most recent call last):
File “/home/pierre/myenv/lib/python3.9/site-packages/lammps.py”, line 248, in init
self.lib = CDLL(join(modpath,"liblammps_s" name + lib_ext),
File “/home/pierre/miniconda3/lib/python3.9/ctypes/init.py”, line 382, in init
self._handle = _dlopen(self._name, mode)
OSError: /home/pierre/myenv/lib/python3.9/site-packages/liblammps_mpi_2.so: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “”, line 1, in
File “/home/pierre/myenv/lib/python3.9/site-packages/lammps.py”, line 254, in init
self.lib = CDLL("liblammps_s" name + lib_ext,RTLD_GLOBAL)
File “/home/pierre/miniconda3/lib/python3.9/ctypes/init.py”, line 382, in init
self._handle = _dlopen(self._name, mode)
OSError: liblammps_mpi_2.so: cannot open shared object file: No such file or directory
=> If I copy liblammps_mpi_2.so to $HOME/myenv/bin/lib64/python3.9/sites-packages :
>>> lmp = lammps.lammps(name='mpi_2')
LAMMPS (29 Oct 2020)
=> But the problem remains :
mpirun -np 2 lmp_mpi_2 -in TEST_LAMMPS_MPI_PYTHON.in gives :
lmp_mpi_2: error while loading shared libraries: liblammps_mpi_2.so: cannot open shared object file: No such file or directory
Primary job terminated normally, but 1 process returned
a non-zero exit code. Per user-direction, the job has been aborted.
lmp_mpi_2: error while loading shared libraries: liblammps_mpi_2.so: cannot open shared object file: No such file or directory
(myenv) (base) pierre@mrsm2p2itc-s30:~/TEST_LAMMPS_PROG_PYTHON/TEST_MPI_2$