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 setup.py 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:

[mkl]
library_dirs = /opt/software/intel/mkl/10.0.1.014/lib/em64t
mkl_libs = mkl, guide
lapack_libs = mkl_lapack
include_dirs = /opt/software/intel/mkl/10.0.1.014/include

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.

1 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:
    PYTHONPATH=$PYTHONPATH:~/lib/python

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.