-
Compile
OpenBLAS
:~$ git clone git://github.com/xianyi/OpenBLAS ~$ cd OpenBLAS && make FC=gfortran ~$ sudo make PREFIX=/opt/OpenBLAS install
If you don't have sudo rights you could set
PREFIX=
to a directory you have write privileges to (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 lineexport LD_LIBRARY_PATH=/opt/OpenBLAS/lib:$LD_LIBRARY_PATH
The
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). -
you can also set the path in your /etc/profile to contain the bellow line:
export LD_LIBRARY_PATH=/opt/OpenBLAS/lib:$LD_LIBRARY_PATH
-
remember to use the command: source /etc/profile
-
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.:~$ sudo -s "echo '/opt/OpenBLAS/lib' > /etc/ld.so.conf.d/openblas.conf"
Once you are done with either option, run
~$ sudo ldconfig
-
-
Install Numpy
-
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 = c define_macros = [('HAVE_CBLAS', None)] FOUND: libraries = ['openblas', 'openblas'] library_dirs = ['/opt/OpenBLAS/lib'] language = c define_macros = [('HAVE_CBLAS', None)] ...
Then just build and install:
~$ python setup.py build && python setup.py install
Install Scipy
将numpy使用的更改过的site.cfg文件拷贝到scipy根目录下,执行相同的编译和安装过程即可。
如果使用低版本的numpy,可以参考
OpenBLAS
git clone git://github.com/xianyi/OpenBLAS
Change into the new directory, then
make FC=gfortran
sudo make PREFIX=/usr/local/ install
The latest lapack release is downloaded, compiled and integreated into OpenBLAS automatically. Ready for the python part!
Numpy
git clone https://github.com/numpy/numpy
Usually one is interested in OpenBLAS because of its fast matrix-matrix multiplication. Whether numpy has a fast dot
function is indicated by the presence of core/_dotblas.so
. However, currently (June 2013) this file is only build, if site.cfg
has an [atlas]
section(also see here and here). There is an interesting thread here with a link to this fix in order to add support for using OpenBLAS for the _dotblas
function. However, right now dovi site.cfg
and:
[default]
library_dirs = /usr/local/lib
[atlas]
atlas_libs = openblas
library_dirs = /usr/local/lib
[lapack]
lapack_libs = openblas
library_dirs = /usr/local/lib
Without the [lapack]
section there were problems with installing scipy
later on. Additionally:
export BLAS=/usr/local/lib/libopenblas.a
export LAPACK=/usr/local/lib/libopenblas.a
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/
Check the detected configuration with python setup.py config
. You should see severalATLAS_INFO
paired with None
. If there is something like 3.8.2
instead of None
then you have an ATLAS install somewhere on your system and numpy won't use OpenBLAS. Get rid of this install (e.g. via apt-get purge
) and rerun the config
command. If ATLAS_INFO
is completely missing then numpy couldn't find your libopenblas*
libraries — you need to check all previous steps again. Now:
python setup.py build
If you look into build/numpy/core
, the file _dotblas.so
should be available.
sudo python setup.py install
installs a system wide numpy that uses OpenBLAS for dot products. This test produces
FAST BLAS
version: 1.8.0.dev-3f10c36
maxint: 9223372036854775807
dot: 0.162246799469
You can change the number of cores OpenBLAS utilizes via OPENBLAS_NUM_THREADS
, e.g.export OPENBLAS_NUM_THREADS=2
results in
:::bash
FAST BLAS
version: 1.8.0.dev-3f10c36
maxint: 9223372036854775807
dot: 0.0949754238129 sec
Scipy
git clone https://github.com/scipy/scipy
Scipy can be installed without any workaround:
python setup.py build
sudo python setup.py install
Make sure that in your sudo
command the variables BLAS
, LAPACK
and LD_LIBRARY_PATH
are correctly set, as shown above! This test script (it has some room for improvement, though ...) works on my machine after the system wide install:
cholesky: 0.080588388443 sec
svd: 1.13443040848 sec
Finally, if you feel good enough (and do a pip install nose
), you can run nose tests via
python -c "import numpy; numpy.test(verbose=2)"
python -c "import scipy; scipy.test(verbose=2)"
祝你成功。。。