I have compiled Octave 4.2.1 from sources with no error. Is there any way to make it use Intel Math Kernel Library?

I have installed it in \opt\intel. When I add it to blas and lapack alternatives with:

sudo update-alternatives --install /usr/lib/libblas.so.3 \
                                 libblas.so.3 \
                                 /opt/intel/compilers_and_libraries/linux/mkl/lib/intel64/libmkl_rt.so \

sudo update-alternatives --install /usr/lib/liblapack.so.3 \
                                 liblapack.so.3 \
                                 /opt/intel/compilers_and_libraries/linux/mkl/lib/intel64/libmkl_rt.so \

Octave doesn't start with the following error:

Intel MKL FATAL ERROR: Cannot load libmkl_core.so.

I have also tried to compile Octave using MKL.

export JAVA_HOME="/usr/lib/jvm/default-java"
export CFLAGS="-O2 -fPIC -DMKL_LP64 -DM_PI=3.1415926535897932384"
export FFLAGS="-O2 -fPIC"
export CPPFLAGS="-I/opt/intel/mkl/include/ -I/opt/intel/mkl/include/fftw/"
export LDFLAGS="-L/opt/intel/mkl/lib/intel64 -L/opt/intel/lib/intel64"
export LD_LIBRARY_PATH="/usr/lib/gcc:/usr/lib/gcc/x86_64-linux-gnu/:/opt/intel/lib/intel64:/opt/intel/mkl/lib/intel64:$LD_LIBRARY_PATH"

./configure --prefix=/opt/octave4_2_mkl --with-blas="-lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -liomp5 -lpthread" --with-lapack="-lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -liomp5 -lpthread" --with-fftw3="-lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -liomp5 -lpthread -lm" --with-fftw3f="-lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -liomp5 -lpthread -lm"

Unfortunately although ./configure does not spit out any errors, when I run 'make' and 'make check' afterwards, the test gets crazy and exits with Signal 6.

up vote 2 down vote accepted

Maybe you have figured it out already, but I have gotten it to work (also Octave 4.2.1) FWIW here are the steps:

Install the MKL library, then set up update-alternatives:

sudo update-alternatives --install /usr/lib/libblas.so libblas.so  /opt/intel/mkl/lib/intel64/libmkl_rt.so 50

sudo update-alternatives --install /usr/lib/libblas.so.3 libblas.so.3 /opt/intel/mkl/lib/intel64/libmkl_rt.so 50

sudo update-alternatives --install /usr/lib/liblapack.so  liblapack.so  /opt/intel/mkl/lib/intel64/libmkl_rt.so 50

sudo update-alternatives --install /usr/lib/liblapack.so.3 liblapack.so.3 /opt/intel/mkl/lib/intel64/libmkl_rt.so 50

Now create a file mkl.conf in /etc/ld.so.conf.d with the paths as entries:



Then run in the terminal

sudo ldconfig

Now use update-alternatives configure to use mkl as your default blas

To check if octave is using mkl, start octave, open a terminal and type

ps aux | grep octave

My output shows 3 processes, the second one looks like

my_user_name  6032  6.4  1.7 1454636 103952 ?      Ssl  08:05   0:01 /usr/local/libexec/octave/4.2.1/exec/x86_64-pc-linux-gnu/octave-gui --force-gui

note the PID (6032 here) then in the terminal run

lsof -p 6032 | grep 'mkl' (change 6032 to your process's PID)

My output is

octave-gu 6032  my_user_name  mem  REG  8,2  5461454 4594702 /opt/intel/compilers_and_libraries_2017.2.174/linux/mkl/lib/intel64_lin/libmkl_rt.so

If it is not using mkl it wouldn't show anything.

You don't need to compile octave with MKL, Octave uses whatever blas library linked to /usr/lib/libblas and /usr/lib/libbapack dynamically.You can switch with update-alternatives and octave will use the one you choose. I compiled octave 4.2.1 before I had MKL, I was using openblas as my blas when I compiled.

In my machine MKL is actually not faster than openblas if the latter is built to optimised for the hardware (rather than installed straight from the repo)

  • I do not know how to compile Openblas myself, but I noticed that when I use python with MKL it is a little bit faster and it uses less resources than Python+Openblas for the same computations (I tested it with inverting matrices only) – Kamil Mróz May 9 '17 at 13:20
  • My bad, I missed something. It turned out that octave does not automatically use /usr/bin/liblas created by update-alternatives. I tried to compile octave explicitly using mkl and got fortran error. But the answer turns out to be simpler Install octave in any way (say from repo), then start it with LD_PRELOAD=/opt/intel/mkl/lib/intel64/libmkl_rt.so octave Now it actually uses mkl and turns out to be faster than openblas. – Icannotlogin May 9 '17 at 20:51
  • Or if you want to benchmark different versions of blas, set up update-alternatives as above then start octave with LD_PRELOAD= /usr/lib/libblas.so octave You can edit octave's .Desktop file so you can just click the launcher. – Icannotlogin May 9 '17 at 21:01

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.