I am trying to install numpy
with OpenBLAS
, however I am at loss as to how the site.cfg
file needs to be written.
When the installation procedure was followed the installation completed without errors, however there is performance degradation on increasing the number of threads used by OpenBLAS from 1 (controlled by the environment variable OMP_NUM_THREADS).
I am not sure if the OpenBLAS integration has been perfect. Could any one provide a site.cfg
file to achieve the same.
P.S.: OpenBLAS integration in other toolkits like Theano, which is based on Python, provides substantial performance boost on increasing the number of threads, on the same machine.
Here's a simpler approach than @ali_m's answer and it works on macOS.
Install a gfortran compiler if you don't have one. E.g. using homebrew on macOS:
Compile
OpenBLAS
from source [installing a release should also work unless you need unreleased bug fixes]:If you don't/can't sudo, set
PREFIX=
to another directory and modify the path in the next step.OpenBLAS does not need to be on the compiler include path or the linker library path.
Download https://github.com/numpy/numpy/blob/master/site.cfg.example to
~/.numpy-site.cfg
, uncomment these lines, and edit them to give the PREFIX path you used in step 2:pip-install numpy and scipy from source (preferably into a virtualenv) without manually downloading them [you can also specify the release versions]:
See the other answers for ways to test it.
Just in case you are using ubuntu or mint, you can easily have openblas linked numpy by installing both numpy and openblas via apt-get as
On a fresh docker ubuntu, I tested the following script copied from the blog post "Installing Numpy and OpenBLAS"
Without openblas the result is:
After I installed openblas with
apt install openblas-dev
, I checked the numpy linkage withand the information is
It doesn't show linkage to openblas. However, the new result of the script shows that numpy must have used openblas:
I just compiled
numpy
inside avirtualenv
withOpenBLAS
integration, and it seems to be working OK.This was my process:
Compile
OpenBLAS
:If you don't have admin rights you could set
PREFIX=
to a directory where you have write privileges (just modify the corresponding steps below accordingly).Make sure that the directory containing
libopenblas.so
is in your shared library search path.To do this locally, you could edit your
~/.bashrc
file to contain the lineThe
LD_LIBRARY_PATH
environment variable will be updated when you start a new terminal session (use$ source ~/.bashrc
to force an update within the same session).Another option that will work for multiple users is to create a
.conf
file in/etc/ld.so.conf.d/
containing the line/opt/OpenBLAS/lib
, e.g.:Once you are done with either option, run
Grab the
numpy
source code:Copy
site.cfg.example
tosite.cfg
and edit the copy:Uncomment these lines:
Check configuration, build, install (optionally inside a
virtualenv
)The output should look something like this:
Installing with
pip
is preferable to usingpython setup.py install
, sincepip
will keep track of the package metadata and allow you to easily uninstall or upgrade numpy in the future.Optional: you can use this script to test performance for different thread counts.
There seems to be a noticeable improvement in performance for higher thread counts. However, I haven't tested this very systematically, and it's likely that for smaller matrices the additional overhead would outweigh the performance benefit from a higher thread count.