Using Intel® MKL in GNU Octave

Published on January 05 , 2011


This guide is intended to help the current Octave users to potentialy improve performance by utilizing Intel® Math Kernel Library (Intel® MKL). It explains how to build 64-bit Octave with Intel MKL for Intel64 based applications.

GNU Octave is a high-level language, primarily intended for numerical computations. It provides a convenient command line interface for solving linear and nonlinear problems numerically, and for performing other numerical experiments using a language that is mostly compatible with Matlab*. It may also be used as a batch-oriented language.

Octave has extensive tools for solving common numerical linear algebra problems, finding the roots of nonlinear equations, integrating ordinary functions, manipulating polynomials, and integrating ordinary differential and differential-algebraic equations. It is easily extensible and customizable via user-defined functions written in Octave's own language, or using dynamically loaded modules written in C++, C, Fortran, or other languages.


Version Information

This application note was created to help users who use Octave to also incorporate the latest versions of Intel MKL 10.3.2 or higher on Linux* platforms on Intel® Xeon® *processor-based systems. Specifically, we'll address Intel MKL version 10.3.2.

This application note applies to Intel Composer XE 2011 and Octave 3.2.4

Note: One can use Intel MKL FFTW3 wrappers in Octave only with Intel MKL 10.3.2 or higher. For using the previous versions please contact the Intel MKL team.

Downloading Intel tools & Octave source code


  1. Intel® MKL contains highly optimized BLAS, LAPACK, and FFT and also the wrappers for FFTW, which can be obtained at: Intel® Math Kernel Library Product Page.
  2. Obtain Intel® C++ and Fortran compilers (Intel MKL and Intel Compilers are now available in a single package - Intel Composer XE ).
  3. To get Octave -

Note: This application note is written specifically for use with the Intel® compilers. Though using Intel MKL with Octave built with other compilers is also possible.


  • Use the following commands to extract the Octave files: 
tar -xf octave-x.x.x.tar.gz  

This will create a directory called octave-x.x.x.

Building Octave

Update configure:

  • Change Please find in the file the lines below and change them  from
1.	if test "$with_fftw" = yes; then   
2.	  have_fftw3_header=no   
3.	  with_fftw3=no   
4.	  AC_CHECK_HEADER(fftw3.h, [have_fftw3_header=yes])   
5.	  if test "$have_fftw3_header" = yes; then   
6.	    AC_CHECK_LIB(fftw3, fftw_plan_dft_1d, [   
7.	      AC_CHECK_LIB(fftw3f, fftwf_plan_dft_1d, [FFTW_LIBS="-lfftw3 -lfftw3f"; with_fftw3=yes])])   
8.	  fi   
9.	fi  


1.	if test "$with_fftw" = yes; then   
2.	  have_fftw3_header=no   
3.	  with_fftw3=no   
4.	  AC_CHECK_HEADER(fftw3.h, [have_fftw3_header=yes])   
5.	  if test "$have_fftw3_header" = yes; then   
6.	    AC_CHECK_LIB(fftw3, fftw_plan_dft_1d, [   
7.	      AC_CHECK_LIB(fftw3f, fftwf_plan_dft_1d, [FFTW_LIBS="-lfftw3 -lfftw3f"; with_fftw3=yes])])   
8.	# Add MKL check   
9.	    AC_CHECK_LIB(mkl_intel_lp64, fftw_plan_dft_1d, [FFTW_LIBS="-Wl,--start-group -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -WI, --end-group -liomp5 -lpthread"; with_fftw3=yes],AC_MSG_RESULT("MKL library not found.  Octave will use the FFTW3 instead."),[-Wl,--start-group -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -Wl,--end-group -liomp5 -lpthread])   
10.	  fi   
11.	fi  


Set environment:

  • Make sure that C/C++ and Fortran compilers are installed and in the PATH. Set LD_LIBRARY_PATH to your compiler (C/C++ and Fortran), and Intel MKL libraries. Also set MKLROOT to you MKL directory.
    There are environment setters in both Intel MKL and Intel CCompiler installation directories: source  .../mkl/bin/ intel64 or like that
  • Set next environment variable: CC, CXX, F77, CFLAGS, CPPFLAGS, LDFLAGS as follow
1.	export CC=icc   
2.	export CXX=icc   
3.	export F77=ifort   
4.	export CFLAGS="-O3 -ipo- -std=c99 -fPIC -DMKL_LP64 -DM_PI=3.1415926535897932384"  
5.	export CPPFLAGS="-I$MKLROOT/include -I$MKLROOT/include/fftw"  
6.	export LDFLAGS="-L$MKLROOT/lib/intel64 -L$MKLROOT/../compiler/lib/intel64"  
7.	export LD_LIBRARY_PATH="$MKLROOT/lib/intel64:$MKLROOT/../compiler/lib/intel64:$LD_LIBRARY_PATH"

Configure and make

Build Octave and install it in the standard place

1.	configure --with-blas="-Wl,--start-group -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -Wl,--end-group -liomp5 -lpthread" --with-lapack="-Wl,--start-group -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -Wl,--end-group -liomp5 -lpthread" 

2.	make   
3.	make install   


Running Octave

Add Octave path to environment variable PATH
Then, you should be able to run Octave


Link/Build Latest Octave with latest MKL

The latest released version of Octave like Octave 4.0.3 haven't provided the same configuration like no option in  Developer can still build the Octave with latest MKL version as below

Install parallel_studio_xe_2017_composer_edition,which include Intel C compiler, Intel Fortran compiler and Intel MKL

source /opt/intel/compilers_and_libraries/linux/bin/ intel64

export CC=icc  

export CXX=icc  

export F77=ifort  

export CFLAGS="-O3 -ipo- -std=c99 -fPIC -DMKL_LP64 -DM_PI=3.1415926535897932384" 

export CPPFLAGS="-I$MKLROOT/include -I$MKLROOT/include/fftw" 

export LDFLAGS="-L$MKLROOT/lib/intel64 -L$MKLROOT/../compiler/lib/intel64" 

export LD_LIBRARY_PATH="$MKLROOT/lib/intel64:$MKLROOT/../compiler/lib/intel64:$LD_LIBRARY_PATH"

./configure --sysconfdir=/etc --with-blas="-Wl,--start-group -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -Wl,--end-group -liomp5 -lpthread -lm" --with-lapack="-Wl,--start-group -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -Wl,--end-group -liomp5 -lpthread -lm" --with-fftw3="-Wl,--start-group -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -Wl,--end-group -liomp5 -lpthread -lm" --with-fftw3f="-Wl,--start-group -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -Wl,--end-group -liomp5 -lpthread -lm" 

make -j8

./run-octave  (try first without install)

When build octave (which depends on much third party software and dependencies), you may run into all kind of build errors, please refer to

In general, a few failures are probably normal. you may go to try use the Octave by ./run-octave and check if simple octave program are work or not.

and please check if intel MKL library are linked in by

[root@hsw-ep01 octave-4.0.3]# source /opt/intel/compilers_and_libraries/linux/bin/ intel64
[root@hsw-ep01 octave-4.0.3]# ldd liboctave/.libs/ =>  (0x00007ffe7b7f9000) => /opt/intel/compilers_and_libraries_2017.0.098/linux/mkl/lib/intel64/ (0x00007fb6d3717000) => /opt/intel/compilers_and_libraries_2017.0.098/linux/mkl/lib/intel64/ (0x00007fb6d1cab000) => /opt/intel/compilers_and_libraries_2017.0.098/linux/mkl/lib/intel64/ (0x00007fb6d01bc000) => /usr/local/lib/ (0x00007fb6cffa0000) => /opt/intel/compilers_and_libraries_2017.0.098/linux/compiler/lib/intel64/ (0x00007fb6cfd71000) => /opt/intel/compilers_and_libraries_2017.0.098/linux/compiler/lib/intel64/ (0x00007fb6cf9e3000) => /opt/intel/compilers_and_libraries_2017.0.098/linux/compiler/lib/intel64/ (0x00007fb6cf778000) => /lib64/ (0x00007fb6cf555000) => /opt/intel/compilers_and_libraries_2017.0.098/linux/compiler/lib/intel64/ (0x00007fb6cf069000) => /opt/intel/compilers_and_libraries_2017.0.098/linux/compiler/lib/intel64/ (0x00007fb6cece1000) => /lib64/ (0x00007fb6ce9df000) => /opt/intel/compilers_and_libraries_2017.0.098/linux/compiler/lib/intel64/ (0x00007fb6ce698000) => /opt/intel/compilers_and_libraries_2017.0.098/linux/compiler/lib/intel64/ (0x00007fb6ce45c000) => /lib64/ (0x00007fb6ce153000) => /opt/intel/compilers_and_libraries_2017.0.098/linux/compiler/lib/intel64/ (0x00007fb6cdee9000) => /lib64/ (0x00007fb6cdccc000) => /opt/intel/compilers_and_libraries_2017.0.098/linux/compiler/lib/intel64/ (0x00007fb6ccdb6000) => /lib64/ (0x00007fb6ccba0000) => /lib64/ (0x00007fb6cc99b000) => /lib64/ (0x00007fb6cc5da000)
        /lib64/ (0x00007fb6d6154000)

And some developer may see other libraries like,  are listed before the intel MKL library. If you still hope to use Intel MKL FFTW, BLAS, LAPACK etc,  you may need build the link manually like

sudo mv /usr/lib64/atlas/ /usr/lib64/atlas/
sudo mv /usr/lib64/atlas/ /usr/lib64/atlas/
sudo mv /lib64/    /lib64/
sudo mv /lib64/ /lib64/

sudo mv /lib64/    /lib64/
sudo mv /lib64/ /lib64/

sudo mv /lib64/    /lib64/
sudo mv /lib64/ /lib64/

sudo rm -rf /usr/lib64/atlas/ /usr/lib64/atlas/ /lib64/ /lib64/  /lib64/ /lib64/ /lib64/ /lib64/
sudo ln -s /opt/intel/compilers_and_libraries/linux/mkl/lib/intel64/ /usr/lib64/atlas/
sudo ln -s /opt/intel/compilers_and_libraries/linux/mkl/lib/intel64/ /usr/lib64/atlas/
sudo ln -s /opt/intel/compilers_and_libraries/linux/mkl/lib/intel64/ /lib64/
sudo ln -s /opt/intel/compilers_and_libraries/linux/mkl/lib/intel64/ /lib64/

sudo ln -s /opt/intel/compilers_and_libraries/linux/mkl/lib/intel64/ /lib64/
sudo ln -s /opt/intel/compilers_and_libraries/linux/mkl/lib/intel64/ /lib64/

sudo ln -s /opt/intel/compilers_and_libraries/linux/mkl/lib/intel64/ /lib64/
sudo ln -s /opt/intel/compilers_and_libraries/linux/mkl/lib/intel64/ /lib64/


Product and Performance Information


Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserverd for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804