A guide to compile Trlinos for beginners
Trilinos is a great collection of numerical algorithms for large scale simulations.
It allows people who have very little programming experience in C/C++ to use advanced numerical techniques and powerful solvers.
Being myself an inexperienced C/C++ programmer and unfamiliar with the linux environment I found extremely difficult to get started. In this article I’d like to describe how to install and compile programs using the Trilinos library.
Using the following steps I have been able to install Trilinos under Ubuntu 12.04 32-bit, Ubuntu 12.10, 13.10 64-bit and two cluster systems that run some kind of linux distribution.
First download the .gz file from their website (you need to enter your email address but its ok you don’t get spam from them!) and then unzip it in your hard drive. (You need of course to replace the name with the name of the file you have downloaded).
1 |
tar xvzf trilinos-11.4.1-Source.tar.gz |
This will create a folder ../trilinos-11.4.1-Source
Go into that folder
1 |
cd trilinos-11.4.1-Source.tar.gz |
Before launching the installation of Trilinos make sure you have cmake 2.8 or greater installed by typing
1 |
cmake --version |
If cmake is not installed in your system or the version is outdated you can get it from here. The installation of cmake should be straightforward (If not, cmake has actually failed its purpose).
Trilinos contains a large number of packages. It is very unlikely that you need all of them, so I highly recommend not to try building all of them at once, but choose only the packages you need. One package I use very often is the Amesos, which provides a nice interface to solve linear systems AX=B using direct methods. Here I’ll describe how to install Amesos and all the packages that Amesos depends on.
For each combination of packages you want to build do the following steps:
Make sure the current directory is the ../trilinos-11.4.1-Source. Under ../trilinos-11.4.1-Source create a new directory. We will install Amesos with mpi support, therefore we will name this directory AMESOS_MPI.
1 2 |
mkdir AMESOS_MPI cd AMESOS_MPI |
Create an empty file and name it for example “do-configure”.
1 |
echo > do-configure |
In the new file add the following lines
1 2 3 4 5 6 7 |
#!/bin/sh EXTRA_ARGS=$@ rm -f CMakeCache.txt ; find . -name CMakeFiles -exec rm -rf {} \; cmake \ |
After the line cmake \ we will give all the options needed to build trilinos.
The first option will tell cmake where we want to install the package we are compiling: We are going to install this under the folder we just created
1 |
-D CMAKE_INSTALL_PREFIX:PATH=/home/../../trilinos-11.0.3-Source/AMESOS_MPI \ |
Next we will tell whether we want a Debug or Release version. I always start with debug version
1 |
-D CMAKE_BUILD_TYPE:STRING=DEBUG \ |
Next we will give the mpi, C++, c and fortran compilers paths. These are usually installed under /usr/bin/ or /usr/local/bin/. If you cannot find them a useful command is the locate mpiCC for example.
1 2 3 |
-D CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/mpiCC \ -D CMAKE_C_COMPILER:FILEPATH=/usr/bin/mpicc \ -D CMAKE_Fortran_COMPILER:FILEPATH=/usr/bin/gfortran \ |
One of the reasons that Trilinos is difficult to unfamiliar users to compile is that the number of available options is overwhelming. Here you can find detailed explanations for every of the following options. In short the first line if set to on improves debugging messages, the second line removes warning message to appear as errors (I’m not quite sure about it) and the last line tells whether we want to print output during compile or not. I always choose to have alot of output.
1 2 3 |
-D HAVE_GCC_ABI_DEMANGLE:BOOL=ON \ -D Trilinos_WARNINGS_AS_ERRORS_FLAGS:STRING="" \ -D CMAKE_VERBOSE_MAKEFILE:BOOL=TRUE \ |
The next set of options are related to the packages. First we instruct cmake not to build all packages and the next two lines instruct cmake to build the Amesos package and all optional packages that depend on Amesos. We also enable the tests and the examples.
1 2 3 4 5 |
-D Trilinos_ENABLE_ALL_PACKAGES:BOOL=FALSE \ -D Trilinos_ENABLE_Amesos:BOOL=ON \ -D Trilinos_ENABLE_ALL_OPTIONAL_PACKAGES:BOOL=ON \ -D Trilinos_ENABLE_TESTS:BOOL=ON \ -D Trilinos_ENABLE_EXAMPLES:BOOL=ON \ |
From the following set of options not all are necessary. The first enables the mpi support and that’s mandatory. The remaining options seem to be optional as I have been able to compile trilinos without using them. I believe the options are self explanatory. Note that the option MPI_EXEC_MAX_NUMPROCS is the number of processors we want to use during compilation.
1 2 3 4 5 6 |
-D TPL_ENABLE_MPI:BOOL=ON \ -D MPI_BASE_DIR:PATH=/usr \ -D MPI_BIN_DIR:PATH=/usr/bin \ -D MPI_EXEC_MAX_NUMPROCS:STRING=2 \ -D MPI_EXEC:FILEPATH="mpirun" \ -D MPI_EXEC_NUMPROCS_FLAG:STRING=-np \ |
While it is possible to let cmake to find the blas and lapack library we can also define the paths in case these are installed somewhere that cmake can’t guess e.g.
1 2 3 4 |
-D BLAS_LIBRARY_NAMES:STRING="blas" \ -D BLAS_LIBRARY_DIRS:PATH=/usr/lib \ -D LAPACK_LIBRARY_NAMES:STRING="lapack" \ -D LAPACK_LIBRARY_DIRS:PATH=/usr/lib \ |
All the above options are sufficient to build the Amesos package with mpi support. However doing so we will be able to use only the default solver. Although the default solver is quite good Amesos provides interface for few other solvers.
If that’s your first attempt to install trilinos it might be better not to try the following options.
The following options are used when you want to install any third party library (TPL). Here we will assume that we have already build the SuperLU and UMFPACK. Note that the following options have the format TPL_xxxxxxx where xxxxxxx is the name of the TPL. Unfortunately this is case sensitive. Yet what is more unfortunate is that there is no way to guess which letters should be upper and lower case. Therefore you need always to check this list and follow precisely the spelling.
First we set on the flag that tells cmake that we want to use the UMFPACK solver. Next we provide the paths for the include and library directories. Using semicolons we can set more that one path. The 4th line is the name of the library without the lib prefix and the suffix which typically is .so, so.3 etc.
1 2 3 4 |
-D TPL_ENABLE_UMFPACK:BOOL=ON \ -D TPL_UMFPACK_INCLUDE_DIRS:PATH="/../UMFPACKv4.4/UMFPACK/Include;/../UMFPACKv4.4/AMD/Include" \ -D TPL_UMFPACK_LIBRARY_DIRS:PATH="/../UMFPACKv4.4/UMFPACK/Lib;/../UMFPACKv4.4/AMD/Lib" \ -D TPL_UMFPACK_LIBRARY_NAMES="umfpack" \ |
For any other TPL we provide the same options. For example to use SuperLU we set the following:
1 2 3 4 |
-D TPL_ENABLE_SuperLU:BOOL=ON \ -D TPL_SuperLU_INCLUDE_DIRS:PATH="/../SuperLU_3.0/SRC" \ -D TPL_SuperLU_LIBRARY_DIRS:PATH="/../SuperLU_3.0" \ -D TPL_SuperLU_LIBRARY_NAMES="superlu_3.0" \ |
Finally we add the 2 last lines in this script:
1 2 |
$EXTRA_ARGS \ ../ |
The last line tells the script to go one level up, therefore you need to make sure that the AMESOS_MPI directory is under the trilinos directory.
Next make the do_configure file executable by setting the right permissions, and run the script
1 2 |
chmod 755 do_configure ./do_configure |
If there are no errors you can build the library by typing
1 |
make -j2 |
After the build has finished you can run some tests if the built was successful.
1 |
ctest -j2 |
The last step is to install the the package by typing
1 |
make install |
Now the package is ready to solve all your problems.