High performance numpy and scipy with MKL

Pre-installation setup

First of all request an interactive session allocating more than one core, for example, to request 4 cores (which will allow you to use 4 threads) use:

qrsh -l i,h_data=1g -pe shared 4

when you get a command prompt on the interactive node follow these steps to install numpy:

create a directory where to install numpy and scipy:

mkdir $HOME/python_packages
cd $HOME/python_packages

load a python module, for example for version 2.7.3 use:

module load python/2.7.3

Build numpy

Get the package

Get the latest numpy package (check on https://pypi.python.org/pypi?%3Aaction=search&term=numpy&submit=search) currently:

wget https://pypi.python.org/packages/source/n/numpy/numpy-1.9.2.tar.gz#md5=a1ed53432dbcd256398898d35bc8e645

Check the package md5sum (it needs to agree with what comes after #md5= in the wget command):

md5sum numpy-1.9.2.tar.gz

Create the site.cfg file

Unpack the package:

tar xvf numpy-1.9.2.tar.gz

# cd into the upacked package:

cd numpy-1.9.2
cp site.cfg.example site.cfg

Edit the file site.cfg so that you will have in it:

 library_dirs = /u/local/compilers/intel/cs-2013-SP1-u1/composer_xe_2013_sp1.3.174/mkl/lib/intel64
 include_dirs = /u/local/compilers/intel/cs-2013-SP1-u1/composer_xe_2013_sp1.3.174/mkl/include
 mkl_libs = mkl_rt
 lapack_libs = mkl_lapack95_lp64

note in the above you will need to substitute:


with the output of (if different):

echo $MKL_LIB



with the output of (if different):

echo $MKL_INC

Modify compiler options

Edit intelccompiler.py

vi numpy/distutils/intelccompiler.py

Make sure that the line starting with self.cc_exe is:

self.cc_exe = 'icc -O3 -g -fPIC -fp-model strict -fomit-frame-pointer -openmp'

Edit the file intel.py:

vi numpy/distutils/fcompiler/intel.py

Make sure that the two lines:

return ['-xhost -openmp -fp-model strict']

are modified to:

return ['-openmp -fp-model strict -fPIC']

Compiling numpy

Issue the command:

python setup.py config --compiler=intelem \
build_clib --compiler=intelem \
build_ext --compiler=intelem \
install --prefix=$HOME/python_packages

Set up environment

export PYTHONPATH so that it will find your $HOME/python_packages:

export PYTHONPATH=$HOME/python_packages/lib/python2.7/site-packages:$HOME/python_packages:$PYTHONPATH

Build scipy

Download the package (currently):

cd $HOME/python_packages
wget https://pypi.python.org/packages/source/s/scipy/scipy-0.16.0.tar.gz#md5=eb95dda0f36cc3096673993a350cde77

Check the package md5sum:

md5sum scipy-0.16.0.tar.gz


tar xvf scipy-0.16.0.tar.gz

Change to the unpackaged directory:

cd scipy-0.16.0

Build with (this will take a while):

python setup.py config --compiler=intelem --fcompiler=intelem \
build_clib --compiler=intelem --fcompiler=intelem \
build_ext --compiler=intelem --fcompiler=intelem \
install --prefix=$HOME/python_packages

To take advantage of the MKL you will need to use more than one thread you can do so by setting the environmental variable MKL_NUM_THREADS, with, for example:


Report Typos and Errors