In a previous post I described how to build an optimized version of NumPy using the Intel compilers and Math Kernel Library (MKL). This post will update those instructions, since it has been a few years and I am now using NumPy 1.6.1, MKL 10.0.1.014 and Red Hat 4.1.1 (kernel 2.6.18-8.el5).
First, copy the file site.cfg.example to site.cfg and open it in an editor like vim. The commented lines in the file give some explanation of how it works. You only need to add the following lines:
[mkl] mkl_libs = mkl_intel_lp64, mkl_intel_thread, mkl_core, guide lapack_libs = mkl_lapack include_dirs = /opt/intel/mkl/10.0.1.014/include library_dirs = /opt/intel/mkl/10.0.1.014/lib/em64t
Notes:
- mkl_intel_thread and guide are only required if you want NumPy to use multi-threaded numerical libraries using OpenMP. If you use these two options, you must also pass the -openmp option to the Fortran compiler (see below).
- The [fftw] section appears to be obsolete. According to the SciPy wiki, support for FFTW was dropped for NumPy >= 1.2. If you need a faster FFT than the fftpack that is now included with NumPy, you may want to check out this project to build FFTW wrappers for Python.
Once you have fixed the config file, the following commands can be used to build NumPy:
LDFLAGS="" FFLAGS="-openmp" python2.7 setup.py build --fcompiler=intelem > stdout.txt 2> stderr.txt python2.7 setup.py install --prefix=/apps/Python/Python-2.7.3/
Notes:
- I set LDFLAGS=”” to make sure that the LDFLAGS set in my .bashrc weren’t used in this build.
- Set FFLAGS=”-openmp” if you specify the libraries mkl_intel_thread and guide in site.cfg
- I like to redirect the standard error and standard output to files that I can view later.
Your configuration is successful if the first few lines of stdout look like this:
F2PY Version 2 blas_opt_info: blas_mkl_info: FOUND: libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'guide', 'pthread'] library_dirs = ['/opt/intel/mkl/10.0.1.014/lib/em64t'] define_macros = [('SCIPY_MKL_H', None)] include_dirs = ['/opt/intel/mkl/10.0.1.014/include'] FOUND: libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'guide', 'pthread'] library_dirs = ['/opt/intel/mkl/10.0.1.014/lib/em64t'] define_macros = [('SCIPY_MKL_H', None)] include_dirs = ['/opt/intel/mkl/10.0.1.014/include'] lapack_opt_info: lapack_mkl_info: mkl_info: FOUND: libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'guide', 'pthread'] library_dirs = ['/opt/intel/mkl/10.0.1.014/lib/em64t'] define_macros = [('SCIPY_MKL_H', None)] include_dirs = ['/opt/intel/mkl/10.0.1.014/include'] FOUND: libraries = ['mkl_lapack', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'guide' , 'pthread'] library_dirs = ['/opt/intel/mkl/10.0.1.014/lib/em64t'] define_macros = [('SCIPY_MKL_H', None)] include_dirs = ['/opt/intel/mkl/10.0.1.014/include'] FOUND: libraries = ['mkl_lapack', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'guide' , 'pthread'] library_dirs = ['/opt/intel/mkl/10.0.1.014/lib/em64t'] define_macros = [('SCIPY_MKL_H', None)] include_dirs = ['/opt/intel/mkl/10.0.1.014/include']
Next step: run some benchmarks!
Pingback: Building SciPy 0.10 with Python 2.7, Intel compilers and MKL on Red Hat Enterprise Linux 5 | shocksolution.com