-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathfortran-regionprofile.f
78 lines (60 loc) · 2.21 KB
/
fortran-regionprofile.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
program fortran_example
use caliper_mod
implicit none
type(BufferedRegionProfile) :: rp
type(ConfigManager) :: mgr
integer :: i, count, argc
real :: innertime, outertime, tottime
logical :: ret
character(len=:), allocatable :: errmsg
character(len=256) :: arg
! Initialize Caliper. Use cali_mpi_init() in an MPI program.
call cali_init()
! (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()
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')
! Create a BufferedRegionProfile instance to query Caliper region times
rp = BufferedRegionProfile_new()
do i = 1, 4
! Start the region profile
call rp%start()
! Add region 'outer' using cali_begin_region()
call cali_begin_region('outer')
! Add another region 'inner' nested under 'outer'
call cali_begin_region('inner')
call cali_end_region('inner')
call cali_end_region('outer')
! Stop the region profile and fetch region times
call rp%stop
call rp%fetch_inclusive_region_times
innertime = rp%region_time('inner')
outertime = rp%region_time('outer')
tottime = rp%total_region_time()
write(*,*) 'Cycle ', i, ': ', tottime, ' sec'
write(*,*) 'outer: ', outertime, ' sec'
write(*,*) ' inner: ', innertime, ' sec'
! Reset the profile
call rp%clear
end do
! Delete the RegionProfile instance
call BufferedRegionProfile_delete(rp)
call cali_end_region('main')
! Compute and flush output for the ConfigManager profiles.
call mgr%flush
call ConfigManager_delete(mgr)
end program fortran_example