Installing An Armadillo and Manually Inserting It Into A Library

Armadillo is a C++ linear algebra library (matrix maths) that supports integer, floating point and complex numbers, as well as a subset of trigonometric and statistics functions.

Download the version you require from SourceForge (you may note the very silly version names) and move it to the source directory, /usr/local/src/ARMADILLO. Extract (tar xvf armadillo-1.1.92.tar.gz and change to that directory.

There are a number of options in the file include/armadillo_bits/config.hpp. In this case we need to uncomment to use LAPACK and BLAS, and load the appropriate environment modules to assist with this (e.g., module load gcc/4.5.2, module load acml/4.3.0-gcc, module load boost/1.44.0-gcc, module load gmp/5.0.1).

Modify include/armadillo_bits/config.hpp to indicate which libraries are currently available on your system. For BLAS and LAPACKuncomment the following lines:


#define ARMA_USE_LAPACK
#define ARMA_USE_BLAS

The Armadillo project uses cmake for it's initial configuration and seems to require relatively new versions, as discovered:


# cmake .
CMake Error: This project requires version 2.6 of CMake. You are running version 2.4.8.

Fortunately, a new version has been already installed (module load cmake/2.6.4).

The next steps simply simply build the program and install it in an appropriate directory. Create an appropriate directory for your armadillo to live in.


mkdir -p /usr/local/armadillo/1.1.92

Change /usr/local/src/ARMADILLO/armadillo-1.1.92/InstallFiles/ArmadilloConfig.cmake


+9 set(ARMADILLO_INCLUDE_DIRS "/usr/local/armadillo/1.1.92/include")
+10 set(ARMADILLO_LIBRARY_DIRS "/usr/local/armadillo/1.1.92/lib64")
+12 include("/usr/local/armadillo/1.1.92/share/Armadillo/CMake/ArmadilloLibraryDepends.cmake")

Change the /usr/local/src/ARMADILLO/armadillo-1.1.92/cmake_install.cmake


+5 SET(CMAKE_INSTALL_PREFIX "/usr/local/armadillo/1.1.92")
+36 FILE(INSTALL DESTINATION "/usr/local/armadillo/1.1.92/include" ...
+42 FILE "$ENV{DESTDIR}/usr/local/armadillo/1.1.92/lib64/libarmadillo.so.1.1.92"
+44 ENDIF(EXISTS "$ENV{DESTDIR}/usr/local/armadillo/1.1.92/lib64/libarmadillo.so.1.1.92")
+46 FILE(INSTALL DESTINATION "/usr/local/armadillo/1.1.92/lib64" TYPE SHARED_LIBRARY FILES
+50 IF(EXISTS "$ENV{DESTDIR}/usr/local/armadillo/1.1.92/lib64/libarmadillo.so.1.1.92")
+52 EXECUTE_PROCESS(COMMAND "/usr/bin/strip" "$ENV{DESTDIR}/usr/local/armadillo/1.1.92/lib64/libarmadillo.so.1.1.92")
+54 ENDIF(EXISTS "$ENV{DESTDIR}/usr/local/armadillo/1.1.92/lib64/libarmadillo.so.1.1.92")
+58 IF(EXISTS "$ENV{DESTDIR}/usr/local/armadillo/1.1.92/share/Armadillo/CMake/ArmadilloLibraryDepends.cmake")
+60 "$ENV{DESTDIR}/usr/local/armadillo/1.1.92/share/Armadillo/CMake/ArmadilloLibraryDepends.cmake"
+63 FILE(GLOB OLD_CONFIG_FILES "$ENV{DESTDIR}/usr/local/armadillo/1.1.92/share/Armadillo/CMake/ArmadilloLibraryDepends-*.cmake")
+65 MESSAGE(STATUS "Old export file \"$ENV{DESTDIR}/usr/local/armadillo/1.1.92/share/Armadillo/CMake/ArmadilloLibraryDepends.cmake\" will be replaced. Removing files [${OLD_CONFIG_FILES}].")
+70 FILE(INSTALL DESTINATION "/usr/local/armadillo/1.1.92/share/Armadillo/CMake" ...
+72 FILE(INSTALL DESTINATION "/usr/local/armadillo/1.1.92/share/Armadillo/CMake" ...

After these changes, a typicall install procedure can follow. If you need to re-run cmake, delete the "CMakeCache.txt".


cmake .
make
make install

Following installation create a environment modules file, in the usual manner e.g.,


cd /usr/local/Modules/modulefiles/armadillo
ln -s .base 1.1.92

The .base file looks like this:


#%Module1.0#####################################################################
##
## $name modulefile
##
set version [lrange [split [ module-info name ] / ] 1 1 ]
set name [lrange [split [ module-info name ] / ] 0 0 ]
set loading [module-info mode load]
set ver [lrange [split $version - ] 0 0 ]
set desc [join [read [ open "/usr/local/Modules/modulefiles/$name/.desc" ] ] ]
proc ModulesHelp { } {
puts stderr "This module sets the envinronment for the Armadillo linear algebra libary v$ver"
}
if { $loading && ![ is-loaded acml/4.3.0-gcc ] } {
module load acml/4.3.0-gcc
}
if { $loading && ![ is-loaded boost/1.44.0-gcc ] } {
module load boost/1.44.0-gcc
}
if { $loading && ![ is-loaded gcc/4.5.2 ] } {
module load gcc/4.5.2
}
if { $loading && ![ is-loaded gmp/5.0.1 ] } {
module load gmp/5.0.1
}
module-whatis "$desc (v$ver)"
prepend-path --delim " " CPPFLAGS -I/usr/local/$name/$ver/include
prepend-path --delim " " CPPFLAGS -I/usr/local/$name/$ver/include/armadillo_bits
prepend-path --delim " " CPPFLAGS -I/usr/local/$name/$ver/lib64

Manually Inserting an Armadillo Into Your Library

An issue that has arisen is that certain R libraries that required armadillo weren't found in its path, despite the environment modules file being loaded. Specifically, with the source of the following available, one library failed.


$ R CMD INSTALL libmlbase/ libmlalgs/ libmlfilters/
..
g++ -I/usr/local/R/2.11.1-gcc/lib64/R/include -I/usr/local/include -fpic -g -O2 -c svo.cc -o svo.o
svo.cc:1:21: error: armadillo: No such file or directory
..
ERROR: compilation failed for package "libmlalgs"

This can be fixed by manually inserting the armadillo directly into the library.


cd libmlalgs
./configure
cd src
g++ -I/usr/local/R/2.11.1-gcc/lib64/R/include -I/usr/local/include
-I/usr/local/armadillo/1.1.92/include
-I/usr/local/armadillo/1.1.92/include/armadillo_bits -fpic -g -O2 -c
svo.cc -o svo.o
cd ../..
R CMD INSTALL libmlbase/ libmlalgs/ libmlfilters/