Compile Trilinos

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).

This will create a folder ../trilinos-11.4.1-Source

Go into that folder

Before launching the installation of Trilinos make sure you have cmake 2.8 or greater installed by typing

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.

Create an empty file and name it for example “do-configure”.

In the new file add the following lines

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

Next we will tell whether we want a Debug or Release version. I always start with debug version

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.

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.

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.

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.

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.

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.

For any other TPL we provide the same options. For example to use SuperLU we set the following:

Finally we add the 2 last lines in this script:

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

If there are no errors you can build the library by typing

After the build has finished you can run some tests if the built was successful.

The last step is to install the the package by typing

Now the package is ready to solve all your problems.

Compile code based on CGAL

CGAL is an amazing computational geometry library that can make your programming life so much simpler and faster. Once you overcome the weird looking coding style becomes a powerful tool.

Here I’ll describe a few modifications that I make on the cgal generated CMakeList.txt that make my life a bit easier and make the files more portable.

In short, the steps are

1) For each project create a new folder and create a default CMakeList.txt file by running cgal_create_cmake_script

This is going to create a default CMakeList.txt file.

If the cgal installation is not on the search path then the cgal_create_cmake_script can be found under path/to/cgal-releases-CGAL-x.xx.x/Scripts/scripts/

To make the script easier to transfer between my CGAL projects I’m doing the following changes:

Selection_007

First I remove the default project name which is taken by the folder name.

Then I add a target name for the project and a target source.

Remove one statement create_single_source_cgal_program(…)

Finally, at the end of the file, I set the project and the executable.

To run cmake you need to create a file with the name ${TARGET}.cpp, in my case test1.cpp. Even an empty file its ok

Then run cmake (don’t forget the space dot) 

If you have to provide the cgal path then add the following option

 

If the configuration is successful you can run make after you have written some code into the file ${TARGET}.cpp

Those modifications allow to copy the same CMakeList.txt files to other projects and build them with a single modification just the very first line. In addition with a few other modifications that will be subject to another post you can add other libraries like deal.ii and OpenSceneGraph

Compile C++ projects with OpenSceneGraph

In this article I’ll show you how to compile an OpenSceneGraph (OSG) C++ project and open it with Qt creator under Ubuntu 13.10 or 13.04.

I’m going to assume that the OSG has been installed on a location known to your system. If you have problems installing the most stable release you can try the following three commands:

Make sure you have a recent version of cmake ( > 2.6)

First create an empty directory for the new OSG project, enter the directory and create an empty CMakeLists.txt file.

Copy the following lines into the empty file:

The only parameter that need to be changed for every project is the name_of_main_file.cpp, which should be given without the suffix *.cpp

Before running the cmake you need to create file name_of_main_file.cpp which can be empty.

You can run cmake from the command line but here I’ll do it from Qt creator.

From Qt creator choose File->Open File or Project

Go to the directory you just created and pick the CMakeLists.txt file

Selection_020

 

This will launch the cmake wizard. In the first step you define the build location. By default this directory is different than the one created above. It is ok to use the same directory if you don’t build the project for different configurations.

Click Next and on the next step click Run CMake to configure the project.

Selection_022

 

Now you can start editing the name_of_main_file.cpp to create you OSG scene.

Qt creator should be able to provide autocompletion and suggestions for all the OSG classes.