Armadillo C++ linear algebra library

From oldwiki.scinet.utoronto.ca
Jump to navigation Jump to search

Armadillo home page: http://arma.sourceforge.net/

armadillo-3.910.0 has been installed on the GPC. There is a module as well:

armadillo/3.910.0

You will, of course, need a compiler. We recommend you use the latest version of the Intel compiler we have available, which at present is

intel/13.1.1


Here is a Makefile that works on the GPC, with the intel and armadillo modules loaded, and which compiles a program called "armadillotest.cxx":

<source lang="bash">

  1. For GPC:
  2. module load intel/13.1.1
  3. module load armadillo/3.910.0
  4. #

CXX=icpc

EXTRA_LIB_FLAGS = -L$(MKLROOT)/lib/intel64 -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm

LIB_FLAGS = $(EXTRA_LIB_FLAGS)

OPT = -O3

  1. ## As the Armadillo library uses recursive templates,
  2. ## compilation times depend on the level of optimisation:
  3. ##
  4. ## -O0: quick compilation, but the resulting program will be slow
  5. ## -O1: good trade-off between compilation time and execution speed
  6. ## -O2: produces programs which have almost all possible speedups,
  7. ## but compilation takes longer

CXXFLAGS = $(OPT) -I$(SCINET_ARMADILLO_INC)

all: armadillotest

armadillotest: armadillotest.cxx $(CXX) $(CXXFLAGS) $(EXTRAFLAGS) -o $@ $< $(LIB_FLAGS)

.PHONY: clean

clean:

</source>

This is the armadillotest.cxx code:

<source lang="cpp">

  1. include "armadillo"
  2. include <vector>
  3. include <ctime>

using namespace arma; using namespace std;

int main()
{
  srand((unsigned)time(0));
  
  mat X = randu<mat>(8, 9);
  X.print("source");
  mat U;
  vec s;
  mat V;
  svd(U,s,V,X);        // use standard algorithm by default
  U.print("U");
  s.print("s");
  V.print("V");
  return 0;
}

</source>