Fortran support

Caliper provides Fortran wrappers for the annotation and ConfigManager APIs. To build Caliper with Fortran support, enable the WITH_FORTRAN option in the CMake configuration:

$ cmake -DWITH_FORTRAN=On ..

Using the Fortran module

The Fortran wrapper module requires Fortran 2003, and Caliper must be built with the same compiler as the target program.

The Caliper fortran module is installed in include/caliper/fortran/ in the Caliper installation directory. Simply add this directory to the application include path and import it with use caliper_mod where needed. Remember to also link libcaliper to the target program.

Caliper Fortran API

The Caliper Fortran API supports a subset of the C and C++ annotation APIs. The simplest options are the cali_begin_region() and cali_end_region() functions.

The Fortran API also supports the Caliper ConfigManager API (ConfigManager API reference). The example in examples/apps/fortran-example.f demonstrates the annotation and ConfigManager APIs for Fortran:

program fortran_example
    use caliper_mod

    implicit none

    type(ConfigManager)   :: mgr

    integer               :: i, count, argc

    logical               :: ret
    character(len=:), allocatable :: errmsg
    character(len=256)    :: arg

    ! (Optional) create a ConfigManager object to control profiling.
    ! Users can provide a configuration string (e.g., 'runtime-report')
    ! on the command line.
    mgr = ConfigManager_new()
    call mgr%set_default_parameter('aggregate_across_ranks', 'false')
    argc = command_argument_count()
    if (argc .ge. 1) then
        call get_command_argument(1, arg)
        call mgr%add(arg)
        ret = mgr%error()
        if (ret) then
            errmsg = mgr%error_msg()
            write(*,*) 'ConfigManager: ', errmsg

    ! Start configured profiling channels
    call mgr%start

    ! A scope annotation. Start region 'main'
    call cali_begin_region('main')

    ! Add another region 'inner' nested under 'main'
    call cali_begin_region('inner')
    count = 4
    ! End the inner region
    call cali_end_region('inner')

    ! End 'main'
    call cali_end_region('main')

    ! Compute and flush output for the ConfigManager profiles.
    call mgr%flush
    call ConfigManager_delete(mgr)
end program fortran_example