Skip to content

Instantly share code, notes, and snippets.

@soldni
Last active April 5, 2017 23:11
Show Gist options
  • Save soldni/2d548cafa7ea4d147aa2bb1c7cd393cc to your computer and use it in GitHub Desktop.
Save soldni/2d548cafa7ea4d147aa2bb1c7cd393cc to your computer and use it in GitHub Desktop.

How to install OpenBLAS & multi-threaded Numpy on RedHat

(main source; other info; even more help)

Step 1: make sure to have gfortran installed

Step 2: clone the OpenBLAS repo.

git clone https://github.com/xianyi/OpenBLAS

Step 3: compile OpenBLAS.

cd OpenBLAS
make CC="gcc -m64" FC="gfortran -m64" RANLIB="ranlib" FFLAGS=" -O2 -fPIC" TARGET= BINARY=64 USE_THREAD=1 GEMM_MULTITHREADING_THRESHOLD=50 NUM_THREADS=16 NO_AFFINITY=1 DYNAMIC_ARCH=1 INTERFACE64=1

Step 4: install OpenBLAS to some directory. I chose /opt/openblas.

sudo make PREFIX=/opt/openblas install

Step 5: create openblas.conf in /etc/ld.so.conf.d/ containing a path to /opt/openblas/lib, then run sudo ldconfig.

Step 6: clone numpy repo from https://github.com/numpy/numpy.git

Step 7: create site.cfg in the root directory of the repo with the following content. Adjust the path to OpenBLAS according to Step 4.

[DEFAULT]
library_dirs = /opt/openblas/lib
include_dirs = /opt/openblas/include

[atlas]
atlas_libs = openblas
libraries = openblas

[openblas]
libraries = openblas
library_dirs =  /opt/openblas/lib
include_dirs =  /opt/openblas/include

Step 8: compile numpy. To ensure that the right Fortran compiler is used, temporarily unset environmental variables.

unset CPPFLAGS
unset LDFLAGS
python setup.py build --fcompiler=gnu95

Step 9: install numpy.

python setup.py install

Step 10: verify that OpenBLAS is properly configured by running the following code

import numpy as np
np.__config__.show()

Step 11: don't forget to set the number of threads OpenBLAS is allowed to use.

export OPENBLAS_NUM_THREADS=32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment