Skip to content

Instantly share code, notes, and snippets.

@BERENZ
Created November 23, 2015 15:01
Show Gist options
  • Select an option

  • Save BERENZ/ff274ebbf00ee111c708 to your computer and use it in GitHub Desktop.

Select an option

Save BERENZ/ff274ebbf00ee111c708 to your computer and use it in GitHub Desktop.
Armadillo with Openblas

Setup Armadillo with openblas

OpenBLAS includes not-only BLAS (multithreaded) but also LAPACK (copy from Netlib).

OpenBLAS

git clone git://github.com/xianyi/OpenBLAS.git
cd OpenBLAS/
git checkout develop     # Dev branch, usually stable. 'master' branch is release branch
make
PREFIX=$HOME/foss/installed/openblas  make install

It is recommended to turn-off CPU throttling before you compile. Other tweaking you could do (disable shared library, disable CPU affinity in Linux (not recommended!), etc.):

setfreq.sh 1.5GHz
TARGET=NEHALEM  USE_THREAD=1 NO_AFFINITY=1 NO_SHARED=1 COMMON_OPT=" -O2 -march=native "  make

Armadillo

  1. Download from homepage
  2. Move it to the folder where you want to install it.
  3. Run ./configure
  4. Don't run make!
  5. Edit the first few lines of armadillo/include/config.hpp so that it resembles something like:
#define ARMA_USE_LAPACK
#define ARMA_USE_BLAS
// #define ARMA_USE_WRAPPER

All this just means that we'll link to BLAS & LAPACK explicitly, so that Armadillo needn't create a wrapper for them. Keep the rest of the contents of config.hpp as it is.

That's all!

Usage

You can run some examples from Armadillo itself, just link with OpenBLAS explicitly:

cd armadillo/examples/
g++ -I ../include -I$HOME/openblas/include -L$HOME/openblas/lib -o example1  example1.cpp -lopenblas
g++ -I ../include -I$HOME/openblas/include -L$HOME/openblas/lib -o example2  example2.cpp -lopenblas

You must also include the LDFLAGS and INCLUDES for Boost library if they are in non-standard locations.

However, to run the executable, you must adjust LD_LIBRARY_PATH:

export LD_LIBRARY_PATH=$HOME/openblas/lib
./example2

If you want to get rid of this, just use static libraries, but make sure to pass -static -pthread -lgfortran:

g++ -static -pthread -I ../include -I$HOME/openblas/include -L$HOME/openblas/lib \
    -o example2  example2.cpp -lopenblas -lgfortran
./example2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment