Sie sind auf Seite 1von 6

Numpy/Scipy with Intel MKL | Intel Developer Zone

http://software.intel.com/en-us/articles/numpyscipy-with-...

App Development

Intel Platform Development

Intel Technologies

Business Resources

What can we help you find today?


Login

or

Numpy/Scipy with Intel MKL


Submitted
Categories: Tags:

by

Vipin Kumar E K...

on

Optimization , Intel Math Kernel Library , Apple Mac OS X* , Linux* , Microso

numpy and mkl , numpy with mkl , mkl numpy , numpy mkl , scipy mkl , scipy with mkl , scipy and mkl , num

NumPy/SciPy Application Note Step 1 - Overview This guide is

intended

NumPy automatically maps o supports these de-fact NumPy (http://en.wikipedia.org/wiki/NumPy) is the

fundamen

a powerful N-dimens sophisticated (broadc tools for integrating useful linear algebra, Besides For its obvious

sc

more

information

SciPy include modules for and more. The SciPy built to work with Nu (http://scipy.org/) for more d and optimization for p

Version Information

This a was c NumP make versio on Lin

The in in this Intel M above Comp above Step 2 - Downloading NumPy and SciPy Source Code

1 of 6

06/17/2013 02:32 PM

Numpy/Scipy with Intel MKL | Intel Developer Zone

http://software.intel.com/en-us/articles/numpyscipy-with-...

downloaded http://www.scipy.org/Download (http://www.scipy.org/Download) Prerequisites Intel MKL

The N code c from:

can

be

obt

Download Download All


/307757.htm) .

a FREE ev the FREE

of

(http://www.intel.com/cd/software/products/asmo-na/eng these can be

ob

Intel

MKL

is

also

Intel Parallel Studio XE 2013 Intel Composer XE 2013 Intel (http://software.intel.com/en-us/intel-cluster-studio-xe/) Cluster Studio XE 2013 (http://software.intel.com/en-us/intel-cluster-studio-xe/) Step 3 - Configuration Use the following

com

$gunzip

numpy-x.x.x

The And

above to

will

create

extract

SciPy,

$gunzip

scipy-x.x.x.ta

The

scipy-x.x.x

direct

Make sure that C++ a and FORTRAN), and Step 4 - Building and Installing NumPy

Change directory to n Create a site.cfg from Edit site.cfg as

follow

Add the following lin the default path for th


[mkl] library_dirs = /opt/intel/mkl/composer_xe_2013/lib/intel64 include_dirs = /opt/intel/mkl/include mkl_libs = mkl_rt lapack_libs =

If

you

are

building

Nu

[mkl] library_dirs = /opt/intel/composer_xe_2013/mkl/lib/ia32 include_dirs = /opt/intel/mkl/include mkl_libs = mkl_rt lapack_libs =

English

2 of 6

06/17/2013 02:32 PM

Numpy/Scipy with Intel MKL | Intel Developer Zone


Modify

http://software.intel.com/en-us/articles/numpyscipy-with-...
in

cc_exe

num

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

Here we use, -O3, opt collapsing IF stateme instruction set availab Run icc --help for compiler flags.

mo

Modify the the Fortra Intel Fortran Compile For ia32 and Intel64

ifort -xhost -openmp -fp-model strict -fPIC

If you are the new intel.py Compile

using ILP6 for your ref install

and

$python setup.py config --compiler=intel build_clib --compiler=intel build_ext --compiler=intel install

Build and Install SciPy Compile and install

$python setup.py config --compiler=intel --fcompiler=intel build_clib --compiler=intel --fcompiler=intel build_ext --compiler=intel --fcompiler=intel install

Setup Library path for Intel MKL and Intel Compilers If you build

NumPY/S

$export If you

LD_LIBRAR NumPY

build

$export

LD_LIBRAR

It is possible that LD_ the standard ones. Th you've set the LD_RU
$export LD_RUN_PATH=/opt/intel/composer_xe_2013/lib/ia32:/opt/intel/composer_xe_2013/mkl/lib/ia32

Note:We recommend user major, and this is bec Appendex A: Example:

Please see below an e provided for illustrati


import numpy as np import time N = 6000 M = 10000

English

3 of 6

06/17/2013 02:32 PM

Numpy/Scipy with Intel MKL | Intel Developer Zone

http://software.intel.com/en-us/articles/numpyscipy-with-...

k_list = [64, 80, 96, 104, 112, 120, 128, 144, 160, 176, 192, 200, 208, 224, 240, 256, 384] def get_gflops(M, N, K): return M*N*(2.0*K-1.0) / 1000**3 np.show_config() for K a b A B in = = = = k_list: np.array(np.random.random((M, np.array(np.random.random((N, np.matrix(a, dtype=np.double, np.matrix(b, dtype=np.double,

N)), dtype=np.double, order='C', copy=False) K)), dtype=np.double, order='C', copy=False) copy=False) copy=False)

C = A*B start = time.time() C C C C C = = = = = A*B A*B A*B A*B A*B

end = time.time() tm = (end-start) / 5.0 print "{0:4}, {1:9.7}, {2:9.7}".format(K, tm, get_gflops(M, N, K) / tm)

Appendix B: Performance Comparison

Please the

(http://software.intel.com/file/41177) to

cl do exam

Please no Intel MK

English

4 of 6

06/17/2013 02:32 PM

Numpy/Scipy with Intel MKL | Intel Developer Zone

http://software.intel.com/en-us/articles/numpyscipy-with-...

For more complete information about compiler optimizations, see our Optimization Notice.

to

po

RSS

Back to Top

Comments
Pierre E. Tue, to 09/04/2012 -

post 10:1

The link to the intel.py file is broken! But I could find it here: http://software.intel.com/sites/default/files/m/d/4/1/d/8/intel.py

Top Pierre E. Wed,

to post 09/05/2012 01:5

Note for Ubuntu and maybe Mac OS X users (<- from what I've read on the net), the building and install parts of Numpy and Scipy should be done in two steps: First to build (with intelem instead of intel for 64 bits processors): python setup.py config --compiler=intel build_clib --compiler=intel build_ext --compiler=intel Then install: sudo python setup.py install Same for Scipy. For numpy to find the libraries (in Ubuntu), add the path to the needed libraries in /etc/ld.so.conf and then run ldconfig Cheers
Top Pierre E. Wed,

to post 09/05/2012 01:5

Note for Ubuntu and maybe Mac OS X users (<- from what I've read on the net), the building and install parts of Numpy and Scipy should be done in two steps: First to build (with intelem instead of intel for 64 bits processors): python setup.py config --compiler=intel build_clib --compiler=intel build_ext --compiler=intel Then install: sudo python setup.py install Same for Scipy. For numpy to find the libraries (in Ubuntu), add the path to the needed libraries in /etc/ld.so.conf and then run ldconfig Cheers
Top Pierre E. Wed,

to post 09/05/2012 02:1

In order to be able to install Scipy you must first set the path to the libraries (as explained in the previous comment) for Numpy, because Scipy import Numpy during the building or installation process.

English

5 of 6

06/17/2013 02:32 PM

Numpy/Scipy with Intel MKL | Intel Developer Zone

http://software.intel.com/en-us/articles/numpyscipy-with-...
Top

Vipin Kumar E K (Intel) Wed,

to post 10/10/2012 2

If you are using the latest NumPy/SciPy, you don't need to replace the intel.py, since has been updated in the NumPy/SciPy source.

Top Craig Finch Wed, to 01/16/2013

post 14:

I used this page as a guide to build NumPy with Intel Composer 2013 and the latest MKL. I would like to clarify the modifications that need to be made to the distutils files: When you edit intelccompiler.py, make sure you are editing the section of the file that corresponds to the command-line flag that you will use when you run setup.py. For example, for a 64-bit system, you need to edit the class called IntelEM64TCCompiler. In the __init__ function, set

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

You 1

bu

python setup.py build --compiler=intelem --fcompiler=intelem

Then modify the file numpy/distutils/fcompiler/intelccompiler.py Modify the class that corresponds to the command-line flags you will use to build NumPy. For a 64-bit system, modify the class IntelEM64TFCompiler. Look for the function called get_flags_arch and add the command-line options as follows:

opt = ['-O3', '-openmp', '-fp-model strict', '-fPIC']

Thanks for posting this article! More information can be found on my blog (see link below).

Craig

Finch

http://
Top

John P. Wed,

topost 03/20/2013 16:0

After building both numpy and scipy using the instructions above, I get the error when importing scipy: ImportError: /usr/lib/atlas/libblas.so.3gf: undefined symbol: _gfortran_st_write_done http://www.scipy.org/Installing_SciPy/BuildingGeneral states that I should NOT use ifort when building numpy ... otherwise I'll get this error ...which defeats the point of using the Intel compilers, right? Any suggestions on how to fix this problem? Thanks! John
Top

Intel DZ Content

Software Resources

Publications

Intel Software Subsidiaries

Content Intel Library Intel Black McAfe (http: Softw Bel (http://softw Developer Magazine Progra Havok (http:/ Code and Downloads

/sites/billboar Intel Software Wind R Forums Intel Paral (http://w Blog Membership Magazine Intel Software Videos Intel Deve Products Newsletter

Intel Corporation (http://intel.com/)

Contact Intel DZ Support

FAQs

Terms of Use (http://www.intel.com/content/www/us/en/legal/terms-of-use.html) *Trademarks (http://www.intel.com/content/www/us/en/legal/trademarks.html) Privacy (http://www.intel.com/content/www/us/en/privacy/intel-online-privacy-notice-summary.html) Cookies (http://www.intel.com/content/www/us/en/privacy/intel-cookie-notice.html)

English

6 of 6

06/17/2013 02:32 PM

Das könnte Ihnen auch gefallen