Reputation: 111
As the title suggests numpy.dot (I think numpy is general) performs much slower after updating my system. The example code that I'm running to compare is:
from numpy import *
import time
A=random.random((1000,1000))
B=random.random((1000,1000))
st=time.time();dot(A,B);end=time.time();print end-st
The following code takes ~0.09s on my other computer (The computer with the problem used to run as fast as the other one), but the code takes ~0.26 on the computer with the problem.
Here are my attempts to solve this problem. My first guess was, 1: ATLAS is not connected to numpy. So, I installed atlas packages using synaptic, libatlas3-bas, libatlas-doc, libatlas-dev, libatlas3gf-bas, libatlas-bas-dev.
After installing this, I checked whether numpy is linked to atlas or not by typing
import numpy.distutils.system_info as sysinfo
sysinfo.get_into('atlas')
The return message is the following:
ATLAS version 3.10.1 built by buildd on Sat Jul 27 19:04:50 UTC 2013:
UNAME : Linux roseapple 3.2.0-37-generic #58-Ubuntu SMP Thu Jan 24 15:28:10 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
INSTFLG : -1 0 -a 1 -l 1
ARCHDEFS : -DATL_OS_Linux -DATL_ARCH_x86SSE2 -DATL_CPUMHZ=1596 -DATL_SSE2 -DATL_SSE1 -DATL_USE64BITS -DATL_GAS_x8664
F2CDEFS : -DAdd_ -DF77_INTEGER=int -DStringSunStyle
CACHEEDGE: 1048576
F77 : /usr/bin/x86_64-linux-gnu-gfortran-4.8, version GNU Fortran (Ubuntu/Linaro 4.8.1-8ubuntu1) 4.8.1
F77FLAGS : -fomit-frame-pointer -mfpmath=sse -O2 -msse2 -fPIC -m64
SMC : /usr/bin/c99-gcc, version gcc (Ubuntu/Linaro 4.8.1-8ubuntu1) 4.8.1
SMCFLAGS : -fomit-frame-pointer -mfpmath=sse -O2 -msse2 -fPIC -m64
SKC : /usr/bin/c99-gcc, version gcc (Ubuntu/Linaro 4.8.1-8ubuntu1) 4.8.1
SKCFLAGS : -fomit-frame-pointer -mfpmath=sse -O2 -msse2 -fPIC -m64
Out[12]:
{'define_macros': [('ATLAS_INFO', '"\\"3.10.1\\""')],
'include_dirs': ['/usr/include/atlas'],
'language': 'f77',
'libraries': ['lapack', 'f77blas', 'cblas', 'atlas'],
'library_dirs': ['/usr/lib/atlas-base/atlas', '/usr/lib/atlas-base']}
So, I assume that it is linked. I also went into numpy/core/ path and typed
$ldd _dotblas.so
and the output is
linux-vdso.so.1 => (0x00007fff16ffa000)
libcblas.so.3 => /usr/lib/libcblas.so.3 (0x00007fa913908000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa9136eb000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa913322000)
libatlas.so.3 => /usr/lib/libatlas.so.3 (0x00007fa912d8f000)
libgfortran.so.3 => /usr/lib/x86_64-linux-gnu/libgfortran.so.3 (0x00007fa912a77000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa912860000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa91255c000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa913d4f000)
libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007fa912320000)
Then, to make sure libcblas.so.3 is linked to ATLAS, I typed
$ /usr/sbin/update-alternatives --config libblas.so.3
There are 4 choices for the alternative libblas.so.3 (providing /usr/lib/libblas.so.3).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/openblas-base/libopenblas.so.0 40 auto mode
* 1 /usr/lib/atlas-base/atlas/libblas.so.3 35 manual mode
2 /usr/lib/libblas/libblas.so.3 10 manual mode
3 /usr/lib/openblas-base/libopenblas.so 30 manual mode
4 /usr/lib/openblas-base/libopenblas.so.0 40 manual mode
Press enter to keep the current choice[*], or type selection number: 1
The following steps didn't fix my problem...
And I realized my CPU throttling was on, and that ATLAS doesn't work well when CPU throttling is on. So, I turned it off using rcconf, and reinstalled Atlas as above and reinstalled Numpy as well... But it doesn't solve the problem...
Now I'm running python 2.7.5+, so I tried reinstalling it as well.. didn't solve the problem.
I checked my memory ..
total used free shared buffers cached
Mem: 5959 2345 3614 0 86 730
-/+ buffers/cache: 1528 4431
Swap: 6133 0 6133
And my memory is free.. and my matlab code runs as fast as before.. so I don't think it is memory problem..
Can anyone help, please? It seems like linear algebra package of numpy is slow... Now, It delays my simulation a lot, so I can't really run my codes. Thank you very much in advance! Let me know if there's any confusion in my question.!
Upvotes: 11
Views: 1797
Reputation: 81
When you say "and reinstalled Numpy as well", did you use pip or apt-get/synaptic?
The Ubuntu (or Debian) packaged version of NumPy available through apt-get install python-numpy
is pre-complied. On the other hand, installing NumPy using pip install numpy
or python setup.py
within the NumPy source directory uses the available compilers to build NumPy from source.
You may then prefer to compile NumPy using ATLAS on your own computer. ATLAS will optimize the NumPy library using the characteristics of your computer (effectively requires turning off CPU throttling).
apt-get install -y python-pip python-dev build-essential
pip install -U cython
apt-get install -y gcc gfortran libatlas-base-dev liblapack-dev
pip install numpy
You may wish to read the ATLAS installation guide or the instructions to build NumPy and SciPy from source on Linux
It may be what you've already done, but then someone else could find it useful!
Upvotes: 6