Tips and tricks - fabm-model/fabm GitHub Wiki

Speed up compilation by including only a subset of biogeochemical models

By default FABM includes biogeochemical models from all "institute directories" under src/models. You can restrict this to a subset of directories by providing -DFABM_INSTITUTES=<INSTITUTES> as argument to cmake. Here, <INSTITUTES> is a semi-colon-separated list of institute names. You may need to enclose this list in quotes to prevent the shell from interpreting the semi-colon.

Efficient debugging by compiling in "debug mode"

While you are developing new biogeochemical models or couplers that link FABM with a new host, it is highly recommended to compile FABM in debug mode. This is done by providing -DCMAKE_BUILD_TYPE=Debug as argument to cmake. In debug mode, FABM performs many more runtime checks. For instance, it verifies whether biogeochemical models actually provide values for the diagnostics they have registered, and it checks the extent of arrays provided by the host model. This comes at the expense of computational performance and is therefore not recommended for production runs. It is very useful for debugging though.

Note that -DCMAKE_BUILD_TYPE=Debug only activates additional checks by FABM itself. It does not activate runtime checks by the compiler, e.g., to catch out-of-bounds array access or use of uninitialized variables. Such checks are valuable. For instance, they are the only way to detect that a model variable is accessed without having been registered. To activate runtime checks, you typically need to set compiler flags such as -fcheck=all for gfortran, or -check all for Intel Fortran. See the next section.

Setting compiler flags to control optimization, runtime checks, etc.

By default, cmake will choose the flags that will be provided to the Fortran compiler. These flags are based on the value of the FFLAGS environment variable, the detected Fortran compiler and the selected build configuration (debug, release, etc). They are internally stored as one general set (CMAKE_Fortran_FLAGS) and one set of additional flags per build configuration (e.g., CMAKE_Fortran_FLAGS_RELEASE, CMAKE_Fortran_FLAGS_DEBUG). When you compile, the general and configuration-specific flags are combined. You can control the flags in several different ways:

  • You can run cmake with default settings first, and then in the build directory run ccmake . This allows you to see and edit all active cmake options, including the compiler flags (after you press T to make advanced options visible).
  • You can provide -DCMAKE_Fortran_FLAGS=<FLAGS> to cmake to override the general set of compiler flags. This can also be achieved by setting the FFLAGS environment variable before the first call to cmake.
  • You can provide flags per build configuration by providing -DCMAKE_Fortran_FLAGS_DEBUG=<FLAGS> or -DCMAKE_Fortran_FLAGS_RELEASE=<FLAGS> to cmake. Remember that these will be added to the general set.
⚠️ **GitHub.com Fallback** ⚠️