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
use iso_c_binding, ONLY : C_INT64_T
implicit none
type(ConfigManager) :: mgr
integer :: i, count, argc
integer(C_INT64_T) :: loop_attribute, iter_attribute
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
endif
endif
! Start configured profiling channels
call mgr%start
! A scope annotation. Start region 'main'
call cali_begin_region('main')
call cali_begin_phase('init')
count = 4
call cali_end_phase('init')
! Annotate a loop. We'll have to find Caliper's built-in "loop"
! attribute first and create a loop iteration attribute, using the region
! name ("mainloop") of our loop.
loop_attribute = cali_find_attribute('loop')
iter_attribute = cali_make_loop_iteration_attribute('mainloop')
call cali_begin_string(loop_attribute, 'mainloop')
do i = 1, count
call cali_begin_int(iter_attribute, i)
! ...
call cali_end(iter_attribute)
end do
call cali_end(loop_attribute)
! 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