I just compiled numpy
inside a virtualenv
with OpenBLAS
integration, and it seems to be working ok. This was my process:
-
Compile
OpenBlas
:git clone git://github.com/xianyi/OpenBLAS cd OpenBLAS && make FC=gfortran sudo make PREFIX=/opt/OpenBLAS install sudo ldconfig
-
Grab the
numpy
source code:git clone https://github.com/numpy/numpy cd numpy
-
Copy
site.cfg.example
tosite.cfg
and edit the copy:cp site.cfg.example site.cfg nano site.cfg
Uncomment these lines:
.... [openblas] libraries = openblas library_dirs = /opt/OpenBLAS/lib include_dirs = /opt/OpenBLAS/include ....
-
Check configuration, build, install (optionally in a
virutalenv
)python setup.py config
The output should look something like this:
... openblas_info: FOUND: libraries = [‘openblas‘, ‘openblas‘] library_dirs = [‘/opt/OpenBLAS/lib‘] language = f77 FOUND: libraries = [‘openblas‘, ‘openblas‘] library_dirs = [‘/opt/OpenBLAS/lib‘] language = f77 ...
Then just build and install:
python setup.py build && python setup.py install
-
Optional: you can use this script to test performance for different thread counts.
OMP_NUM_THREADS=1 python build/test_numpy.py FAST BLAS version: 1.8.0.dev-27690e3 maxint: 9223372036854775807 dot: 0.100896406174 sec OMP_NUM_THREADS=8 python test_numpy.py FAST BLAS version: 1.8.0.dev-27690e3 maxint: 9223372036854775807 dot: 0.0660264015198 sec
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.
lapack_lite.so
is correctly linked against thelibopenblas.so
you just built? You can callldd /<path-to-site-packages>/numpy/linalg/lapack_lite.so
- if you installed OpenBLAS withPREFIX=/usr/local
you should see something likelibopenblas.so.0 => /usr/local/lib/libopenblas.so.0
in the output. – ali_m Jan 30 at 18:01python setup.py clean
andpython setup.py build
and look for any error messages during the compilation. – ali_m Jan 30 at 18:14sudo ldconfig
after installing OpenBLAS if you haven‘t already (I‘ve added this line to my answer) – ali_m Jan 30 at 18:21