[Numpy-discussion] Slow Numpy/MKL vs Matlab/MKL
Oleg Mikulya
olegmikul at gmail.com
Tue Dec 6 17:31:21 EST 2011
Hi,
How to make Numpy to match Matlab in term of performance ? I have tryied
with different options, using different MKL libraries and ICC versions,
still Numpy is below Matalb for certain basic tasks by ~2x. About 5 years
ago I was able to get about same speed, not anymore. Matlab suppose to use
same MKL, what it the reason of such Numpy slowness (beside one, yet
fundamental, task) ?
My conditions:
*site.cfg*:
<<<->>>
[DEFAULT]
library_dirs = /opt/intel/composer_xe_2011_sp1.7.256/mkl/lib/intel64
include_dirs = /opt/intel/composer_xe_2011_sp1.7.256/mkl/include
mkl_libs = mkl_mc3, mkl_intel_thread, mkl_intel_lp64, mkl_core
blas_libs = mkl_blas95_lp64
lapack_libs = mkl_lapack95_lp64
[lapack_opt]
library_dirs = /opt/intel/composer_xe_2011_sp1.7.256/mkl/lib/intel64
include_dirs = /opt/intel/composer_xe_2011_sp1.7.256/mkl/include
libraries = mkl_lapack95_lp64
[blas_opt]
library_dirs = /opt/intel/composer_xe_2011_sp1.7.256/mkl/lib/intel64
include_dirs = /opt/intel/composer_xe_2011_sp1.7.256/mkl/include
libraries = mkl_blas95_lp64
<<<->>>
*intelccompiler.py*:
<<<->>>
...
linker_flags = '-O3 -openmp -lpthread -xHOST -fPIC -parallel -m64'
compiler_opt_flags = '-static -xHOST -O3 -fPIC -mkl=parallel -ipo -parallel
-m64'
icc_run_string = 'icc ' + compiler_opt_flags
icpc_run_string = 'icpc ' + compiler_opt_flags
linker_run_string = 'icc ' + linker_flags + ' -shared '
...
<<<->>>
*test.py*
<<<->>>
import numpy
from numpy import random
import time
n=10000
m=10000
A=random.rand(n,m)
b=numpy.ones((n,1))
tic = time.time()
x=numpy.linalg.solve(A,b)
toc = time.time()
dt=toc-tic
print "lin eq %7.1f " %dt
tic = time.time()
x=numpy.linalg.eig(A)
toc= time.time()
dt=toc-tic
print "eig %7.1f " %dt
tic = time.time()
x=numpy.linalg.svd(A)
toc= time.time()
dt=toc-tic
print "svd %7.1f " %dt
<<<->>>
*test.m*
<<<->>>
n=10000;
m=10000;
A=rand(n,m);
b=ones(n,1);
disp('lin eq');
tic;
x=A\b;
toc;
disp('Eig');
tic;
x=eig(A);
toc;
disp('SVD');
tic;
x=svd(A);
toc;
<<<->>>
Results: Linux_2.6.32...x86_64, Scientific Linux 6.1, i7, 12 GB RAM, python
2.7, Numpy 1.6, Matlab R2011b:
Test Python/Numpy Matlab
lin eq 14.6 14.9
eig 750.8 312.8
svd 431.9 271.2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20111206/136ae387/attachment.html>
More information about the NumPy-Discussion
mailing list