Warm tip: This article is reproduced from stackoverflow.com, please click
linux openblas

Override BLAS with LD_LIBRARY_PATH

发布于 2020-03-27 15:46:19

I usually switch between blas versions using sudo update-alternatives .... However, I need to get it to work without sudo. I have tried several options, but none seem to work.

I have the following FORTRAN code to test if I have successfully switched libraries

      PROGRAM BLASTEST
         IMPLICIT NONE

         CALL MKL_Set_Num_Threads(1)
         CALL openblas_set_num_threads(1)

      END PROGRAM BLASTEST

I have intel MKL set as the preferred alternative, so when I compile using the following command, it results in an error that openblas_set_num_threads cannot be found.

gfortran -o test test.f -lblas

I have tried the following methods to get it to link with openblas instead, but it keeps linking with MKL:

  • Create a symbolic link from ~/.local/alternatives/libblas.so.3-x86_64-linux-gnu to /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3 and add ~/.local/alternatives to LD_LIBRARY_PATH

  • Same method as before, but also add it to LIBRARY_PATH

  • Compile using the following command gfortran -o test test.f -L/usr/lib/x86_64-linux-gnu/openblas/libblas.so.3 -lblas

Any help would be greatly appreciated

Questioner
Thijs Steel
Viewed
106
Knud Larsen 2020-02-01 00:41

Override BLAS with LD_LIBRARY_PATH

Set openblas before "Intel MKL Blas" in the search path:

The common method is simply to set "the preferred" first in the LD_LIBRARY_PATH when compiling :

export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/openblas:$LD_LIBRARY_PATH && [other command]