Compilation of Elmer on Linux using Cmake

From Elmer Wiki
Jump to: navigation, search

As of February 2015, the main Elmer distribution channel has changed to GitHub. The code is found under the elmerfem-link.

Retrieving the source

There are different ways of retrieving the source code from the repository. If you check on the repository, you find hints for retrieving a ZIP-file or using HTTPS,SSH or Subversion protocol for downloading. The most convenient way is to use git itself. The checkout command is

git clone git://

Some network connection settings (e.g., proxies) do not allow for the git-protocol, hence one could replace it with

git clone

Please, bear in mind that there are different branches in this repository. The most important branch, "devel", contains the latest updates of Elmer and preferentially should be used for compilation. It should be the default branch (see below how to verify). There are special branches for different projects within Elmer (e.g. "elmerice" - see instructions on here). In order to check the branch one is in (and also how up-to-date the current copy of the repository is), do a

git status

which should report something like

git status
On branch master
Your branch is behind 'origin/master' by 330 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

The example above shows that git usually gives instructions on what actions to take. In order to change to the branch "devel" one has to enter

git checkout devel

Compilation using Cmake

Naturally, if you use Cmake for compilation one has to take care that the package (included in most standard Linux distributions) is installed. A version of Cmake 2.8.9 or newer is needed for successful configuration. Additionally one needs GNU make for the building process. Cmake allows for a lot of automated testing of the system, nevertheless, the user can add directives either as arguments to the cmake command or within a toolchain file. An installation script could read as (script proved to work on Linux Mint 17)


# Example build-script for Elmer on Linux Mint 17(LTS)


# Installation directory (set these!)
TIMESTAMP=$(date +"%m-%d-%y")

echo "Building Elmer from within " ${BUILDDIR}
echo "using following toolchain file " ${TOOLCHAIN}
echo "installation into " ${IDIR}
ls -ltr


    -DCMAKE_C_COMPILER=/usr/bin/gcc \
    -DCMAKE_Fortran_COMPILER=/usr/bin/gfortran \
    -DWITH_Mumps:BOOL=TRUE \
    -DWITH_Hypre:BOOL=TRUE \

make -j4 && sudo make install

sudo rm /usr/local/Elmer-devel
sudo ln -s $IDIR /usr/local/Elmer-devel

This should build a parallel (=MPI) version of Elmer including the parallel sparse matrix solver packages of Hypre and MUMPS - you need to install the "devel" versions (i.e., versions containing the header files) in advance. Installation will be done under /usr/local/Elmer-devel, which is expected to be a symbolic link (please, make sure that this is the case). If you lack sudo-rights, just change the installation directory to a path that provides you the correct permissions. Furthermore, ElmerGUI will be compiled - this expects the "devel" versions of OpenCascade, QWT and a binary (should the post-processing link work) of ParaView to be installed. Clearly, the user also has to take care that the GNU C (gcc), Fortran (gfortran) and C++ (g++) alongside a MPI library (e.g. OpenMPI) is installed on the system. The optional (actually, toolchain files should be avoided in native compilations) toolchain file for Linux Mint 17, Elmer-linux-linuxmint17.cmake, reads as

# CMake toolchain file for building on Linux Mint 17 (LTS) 64bit
# CSC - IT Center for Science Ltd.
# Version: 0.1


# Specify the cross compilers (serial)
SET(CMAKE_Fortran_COMPILER gfortran)

# Specify the cross compilers (parallel)
SET(MPI_Fortran_COMPILER mpif90)

# Compilation flags (i.e. with optimization)

It is also important to create the separate build directory (in this case builddir under elmerfem), or, in case of an earlier compilation, to clear it from old files. With all these per-requisites in place, the compilation the simply is triggered by running the script (don't forget to make it executable). Hint: if you need to use sudo rights to install, sometimes the -E option is in order to redirect the current environment to the process.

Adjusting the environment

You should (best place would be in ~/.bashrc) alter/create the following environment variables

export ELMER_HOME="/usr/local/Elmer-devel"
export PATH="$PATH:$ELMER_HOME/bin"

in order to be able to utilize Elmer without being forced to give the complete paths to the executable/libraries.

Fast Recompilation

Sometimes the source has been already built but changes have been applied to some module. In this case the fastest way to compile is to command in the build dir as follows:

Assuming changes have been made to the MagnetoDynamics2D.F90, then

make MagnetoDynamics2D/fast install/fast