0

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

Thijs Steel
  • 1,190
  • 7
  • 16
  • 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]` – Knud Larsen Jan 31 '20 at 11:19
  • That seems to do the trick on load time. I still can't get it to compile with openblas, but with your way, I at least get to use openblas at runtime which is sufficient for my use case. If you make an answer i'll accept it. – Thijs Steel Jan 31 '20 at 12:54

1 Answers1

1

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]
Knud Larsen
  • 5,753
  • 2
  • 14
  • 19