Numpy SVD appears to parallelize on Mac OSX, but not on my Ubuntu virtual machine

馋奶兔 提交于 2019-12-04 15:14:24
ali_m

I suspect that the version of numpy on your cloud VM is only linked to the reference CBLAS library (*/usr/lib/libblas/libblas.so.3.0). This is single-threaded and much slower than other optimized BLAS implementations such as OpenBLAS and ATLAS.

You can confirm this by using ldd to check which libraries are dynamically linked by numpy at runtime:

~$ ldd /usr/lib/python2.7/dist-packages/numpy/core/_dotblas.so

You will probably see a line like this:

...
libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f98445e3000)
...

/usr/lib/libblas.so.3 is a symbolic link. If you follow the chain of links using readlink, you'll probably see something like this:

~$ readlink -f /usr/lib/libblas.so.3
/usr/lib/libblas/libblas.so.3.0

This is the slow, single-threaded CBLAS library. Assuming you have root access, the easiest solution is probably to install OpenBLAS via apt-get:

~$ sudo apt-get install libopenblas-base libopenblas-dev

When I installed this package on my server, it updated the symlink at /usr/lib/libblas.so.3 to point at the OpenBLAS library rather than CBLAS:

~$ readlink -f /usr/lib/libblas.so.3
/usr/lib/openblas-base/libblas.so.3

Hopefully that should be enough to get you going with a faster BLAS library.

If, for whatever reason, you can't solve this using apt-get, I've previously written some instructions for building numpy and OpenBLAS from source which you can find here. I've also written some instructions here for manually symlinking to a different BLAS library using update-alternatives.


*The paths I refer to in my answer are the defaults for a server running Ubuntu 14.10, where I have installed numpy using apt-get. They might differ a bit depending on your version of Ubuntu and the way in which you've installed numpy.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!