Installing numpy with the Intel Math Kernel Library (mkl)

Today I installed numpy on a cluster. Normally, as a Gentoo admin, I just install things with emerge, and all the details are taken care of automagically. However, this cluster runs Red Hat Enterprise, and I don’t have admin privileges, so I had to install numpy in my home directory. I installed 1.0.4, to match the version used on another system. You may not need to do this for more recent versions of numpy, which may have an improved setup script. The overall process is:

  1. Unpack the tar file with: tar xfvz numpy-1.0.4.tar.gz
  2. cd numpy-1.0.4
  3. cp site.cfg.example site.cfg
  4. vi site.cfg
  5. python install –home=~

Numpy tries to find the installed system linear algebra libraries BLAS, ATLAS, and LAPACK. If it can’t find them, you will miss out on some dramatic speed improvements. This cluster happens to have the Intel Math Kernel Libraries (mkl), which replace the open source versions. To tell numpy where to find mkl, you have to edit the file site.cfg. It is not immediately obvious what to do–at first I tried to add the mkl path and library names to the blas_opt and lapack_opt sections, but that didn’t work. I had to add a section as follows:

library_dirs = /opt/software/intel/mkl/
mkl_libs = mkl, guide
lapack_libs = mkl_lapack
include_dirs = /opt/software/intel/mkl/

I didn’t have to uncomment the blas_opt or lapack_opt sections at all. I got this idea from a file I found on the scipy web site.

Leave a comment if this does or does not work for you.


One thought on “Installing numpy with the Intel Math Kernel Library (mkl)

  1. One thing I forgot to mention: this process installs packages under “/home/yourname/lib/python”. You have to tell Python to look for packages in that location. One quick way is to add that directory to your PYTHONPATH environment variable:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s