How can I get NumPy to use OpenBlas in Ubuntu?
I have both BLAS and OpenBLAS installed:
$ dpkg -l \*blas\* | grep ^i
ii libblas-dev 1.2.20110419-7 amd64 Basic Linear Algebra Subroutines 3, static library
ii libblas3 1.2.20110419-7 amd64 Basic Linear Algebra Reference implementations, shared library
ii libopenblas-base 0.2.8-6ubuntu1 amd64 Optimized BLAS (linear algebra) library based on GotoBLAS2
ii libopenblas-dev 0.2.8-6ubuntu1 amd64 Optimized BLAS (linear algebra) library based on GotoBLAS2
However, NumPy still says that OpenBLAS is not available:
>> np.__config__.show()
blas_info:
libraries = ['blas']
library_dirs = ['/usr/lib']
language = f77
lapack_info:
libraries = ['lapack']
library_dirs = ['/usr/lib']
language = f77
atlas_threads_info:
NOT AVAILABLE
blas_opt_info:
libraries = ['blas']
library_dirs = ['/usr/lib']
language = f77
define_macros = [('NO_ATLAS_INFO', 1)]
atlas_blas_threads_info:
NOT AVAILABLE
openblas_info:
NOT AVAILABLE
lapack_opt_info:
libraries = ['lapack', 'blas']
library_dirs = ['/usr/lib']
language = f77
define_macros = [('NO_ATLAS_INFO', 1)]
atlas_info:
NOT AVAILABLE
lapack_mkl_info:
NOT AVAILABLE
blas_mkl_info:
NOT AVAILABLE
atlas_blas_info:
NOT AVAILABLE
mkl_info:
NOT AVAILABLE
How can I fix this?
I don't think I can just delete libblas3
, because of which many things affect it, including those libblas-dev
that even depend on libopenblas-dev
.
I tried
$ sudo apt-get install --reinstall python-numpy
but it did not help.
This is especially surprising because all of the files *.so
in numpy
are linked to OpenBLAS:
$ ldd `find /usr/lib/python2.7/dist-packages/numpy -name \*\.so` | grep libblas
libblas.so.3 => /usr/lib/libblas.so.3 (0x00007fba2ac96000)
libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f04f7f54000)
libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f9a941a9000)
$ ls -l /usr/lib/libblas.so.3 /etc/alternatives/libblas.so.3
lrwxrwxrwx 1 root root 35 Oct 22 2014 /etc/alternatives/libblas.so.3 -> /usr/lib/openblas-base/libblas.so.3
lrwxrwxrwx 1 root root 30 Oct 6 2014 /usr/lib/libblas.so.3 -> /etc/alternatives/libblas.so.3
source to share
On Ubuntu 16.10, you can simply
$ apt install libopenblas-base
and activate your preferred BLAS implementation with
$ update-alternatives --config libblas.so.3
I did this and ran
import numpy as np a1 = np.random.rand(10000, 10000) a2 = np.random.rand(10000, 10000) np.dot(a1, a2)
with libblas (2m38s only, single core load only) and libopenblas (0m18s, multi core load)
EDIT: This was with Python and numpy installed via the official Ubuntu repositories, not pip.
source to share