4

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 uninstall libblas3, beacuse many things depend on it, including libblas-dev, on which even libopenblas-dev depends.

I tried

$ sudo apt-get install --reinstall python-numpy

but this didn't help.

This is especially surprising, because all of the *.so files in numpy link 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
MWB
  • 11,740
  • 6
  • 46
  • 91

2 Answers2

4

On Ubuntu 16.10 you can just

$ apt install libopenblas-base

and activate your prefered implementation of BLAS using

$ update-alternatives --config libblas.so.3

I did it 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, single core load only) and libopenblas (0m18s, multi core load)

EDIT: This was with Python and numpy installed through Ubuntu's official repositories and not with pip.

2

Based on the ldd output, NumPy must already be linked with OpenBLAS. It just doesn't know it, because it's linked via /usr/lib/libblas*, which it sees as generic BLAS.

MWB
  • 11,740
  • 6
  • 46
  • 91
  • 4
    That answer, though accepted, didn't mention what exactly to do about it. What can one do to get NumPy to "know" that it's linked with OpenBLAS? – Rafael_Espericueta Aug 09 '15 at 12:58
  • Although I'm curious what the answer to that is, it may not be pertinent in my case. My outputs are almost identical to those in this post, except for the one line which prompted this accepted solution - ldd 'find /usr/lib/python2.7/dist-packages/numpy -name \*\.so' | grep libblas In my case, it didn't find any such files in that directory. So what might that mean in my case? And most importantly, what should I do about it? – Rafael_Espericueta Aug 09 '15 at 13:06
  • @Rafael_Espericueta There is no need to do anything in my case. In your case, assuming you are describing it correctly, you probably didn't even install python blas from apt. (I don't really want to second-guess that you might have done, or what your goals are) – MWB Aug 10 '15 at 00:48