block-hczhai / pyblock3-preview

pyblock3: an efficient python block-sparse tensor library
GNU General Public License v3.0
21 stars 12 forks source link

libmkl_def.so.1 file error #13

Closed cvyaw1 closed 1 month ago

cvyaw1 commented 1 month ago

I installed the latest version 0.2.8 via pip and am obtaining Intel MKL FATAL ERROR: Cannot load libmkl_def.so.1., since the file does not exist in the specific place it's looking for it.

I've tried setting the LD_LIBRARY_PATH environment variable to include the MKL library directories, but the issue persists. I get this error: ld.so: object '/...' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.

The libmkl_avx.so.1 and libmkl_core.so.1 libraries are present in the $MKLROOT/lib directory. The libmkl_def.so.1 library is also present in the $MKLROOT/lib directory.

The error can be recreated by setting up a Python environment using conda with pyblock3 and pyscf (numpy<1.23) installed and running one of the algebra/tests that are part of pyblock3 (in particular the cpp ones, rather than python). Further, the errors are only caused if the argument in creating the Hamiltonian is set to Flat=True.

The full error message: INTEL MKL ERROR: /home/../miniforge3/envs/tcc/lib/python3.10/site-packages/pyblock3.libs/libmkl_def.so.1: cannot open shared object file: No such file or directory. Intel MKL FATAL ERROR: Cannot load libmkl_def.so.1.

The content of that folder (i.e. includes the libmkl_core but not the libmkl_def.so.1).

libgomp-f7e03b3e.so.1.0.0 libmkl_core-a1f8e95a.so.1 libmkl_avx2.so.1 libmkl_gnu_thread-76126a9d.so.1 libmkl_avx512.so.1 libmkl_intel_lp64-eeafede9.so.1

Is there an incompatibility issue between the libraries? Why must it search for the file in this specific location? Many thanks!

hczhai commented 1 month ago

Please make sure the LD_PRELOAD environment variable is not set, by export LD_PRELOAD= before running any tests.

cvyaw1 commented 1 month ago

Thank you for your response - unfortunately that already was the case. I've tried both ways.

(tcc_dmrg) ...:~/miniforge3/envs/tcc_dmrg/lib/python3.10/site-packages/pyblock3/algebra/tests$ echo $LD_PRELOAD

(tcc_dmrg) ...:~/miniforge3/envs/tcc_dmrg/lib/python3.10/site-packages/pyblock3/algebra/tests$ export LD_PRELOAD=

(tcc_dmrg) ...:~/miniforge3/envs/tcc_dmrg/lib/python3.10/site-packages/pyblock3/algebra/tests$ python test_fermion_cpp.py

Full Tests for fermion CPP backend

INTEL MKL ERROR: /home/.../miniforge3/envs/tcc_dmrg/lib/python3.10/site-packages/pyblock3.libs/libmkl_def.so.1: cannot open shared object file: No such file or directory.

Intel MKL FATAL ERROR: Cannot load libmkl_def.so.1.

(tcc_dmrg) ...:~/miniforge3/envs/tcc_dmrg/lib/python3.10/site-packages/pyblock3/algebra/tests$ python test_fermion_python.py

Full Tests for fermion python backend

........................................


Ran 40 tests in 0.965s

OK

hczhai commented 1 month ago

Thanks for the feedback.

It is likely that you are using an AMD CPU. You can do cat /proc/cpuinfo to check the CPU type. To make MKL work for AMD CPU, we need the following fix. Please type the following commands in a non-temporary directory in your terminal:

echo "int mkl_serv_intel_cpu_true() { return 1; }" > fixcpu.c
gcc -shared -fPIC -o libfixcpu.so fixcpu.c
export LD_PRELOAD=$PWD/libfixcpu.so

Then you can execute the pyblock3 scripts, and the libmkl_def.so.1 error will disappear.

cvyaw1 commented 1 month ago

Thank you kindly! I'm indeed running on AMD and this solves the issue. It would perhaps be helpful to add this to the readme for anyone else in future.