GCC Code Coverage Report


Directory: src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 0.0% 0 / 0 / 2
Functions: 0.0% 0 / 0 / 2
Branches: 0.0% 0 / 0 / 18

other/m_timer.f90
Line Branch Exec Source
1 !> @brief Basic module for MPI-aware timing utilities
2 module m_timer
3 use m_common, only: wp
4 implicit none
5
6 private
7 public :: BasicTimer
8
9 !> @brief BasicTimer object to measure elapsed time
10 type BasicTimer
11
12 !> MPI communicator for the timer
13 integer :: comm
14 !> My rank in the communicator
15 integer :: my_rank
16
17 !> Starting time
18 real(wp) :: start_time
19 !> Ending time
20 real(wp) :: end_time
21 !> Elapsed time in seconds on this rank
22 real(wp) :: elapsed_time
23 !> Number of times the timer has been started
24 integer :: start_count
25 !> Elapsed time in seconds on all ranks
26 real(wp), allocatable :: elapsed_times(:)
27 contains
28 procedure :: init => timer_init
29 procedure :: start => timer_start
30 procedure :: stop => timer_stop
31 procedure :: minval => timer_minval
32 procedure :: maxval => timer_maxval
33 procedure :: avgval => timer_avgval
34 procedure :: summary_string => timer_summary_string
35 final :: timer_destroy
36 end type BasicTimer
37
38 ! Module procedure interfaces for submodule
39 interface
40 !> @brief Initialize the timer
41 !>
42 !> @param[inout] this The BasicTimer object to initialize
43 !> @param[in] comm _(optional)_ MPI communicator (default: PETSC_COMM_WORLD)
44 module subroutine timer_init(this, comm)
45 class(BasicTimer), intent(inout) :: this
46 integer, intent(in), optional :: comm
47 end subroutine
48
49 !> @brief Destroy the timer object
50 !>
51 !> @param[inout] this The BasicTimer object to destroy
52 module subroutine timer_destroy(this)
53 type(BasicTimer), intent(inout) :: this
54 end subroutine
55
56 !> @brief Start the timer
57 !>
58 !> @param[inout] this The BasicTimer object to start
59 !> @param[in] reset _(optional)_ Whether to reset the timer (default: .false.)
60 module subroutine timer_start(this, reset)
61 class(BasicTimer), intent(inout) :: this
62 logical, intent(in), optional :: reset
63 end subroutine
64
65 !> @brief Stop the timer
66 !>
67 !> @param[inout] this The BasicTimer object to stop
68 !> @param[in] print_summary _(optional)_ Whether to print summary (default: .false.)
69 !> @param[in] prefix _(optional)_ Prefix for the summary string
70 module subroutine timer_stop(this, print_summary, prefix)
71 class(BasicTimer), intent(inout) :: this
72 logical, intent(in), optional :: print_summary
73 character(len=*), intent(in), optional :: prefix
74 end subroutine
75
76 !> @brief Get the minimum elapsed time across all ranks
77 !>
78 !> @param[in] this The BasicTimer object to query
79 !>
80 !> @return The minimum elapsed time
81 module function timer_minval(this) result(min_time)
82 class(BasicTimer), intent(in) :: this
83 real(wp) :: min_time
84 end function
85
86 !> @brief Get the maximum elapsed time across all ranks
87 !>
88 !> @param[in] this The BasicTimer object to query
89 !>
90 !> @return The maximum elapsed time
91 module function timer_maxval(this) result(max_time)
92 class(BasicTimer), intent(in) :: this
93 real(wp) :: max_time
94 end function
95
96 !> @brief Get the average elapsed time across all ranks
97 !>
98 !> @param[in] this The BasicTimer object to query
99 !>
100 !> @return The average elapsed time
101 module function timer_avgval(this) result(avg_time)
102 class(BasicTimer), intent(in) :: this
103 real(wp) :: avg_time
104 end function
105
106 !> @brief Get a summary string of the timer
107 !>
108 !> @param[in] this The BasicTimer object to summarize
109 !>
110 !> @return A string summarizing the timer's statistics
111 module function timer_summary_string(this) result(summary)
112 class(BasicTimer), intent(in) :: this
113 character(len=40) :: summary
114 end function
115 end interface
116
117 end module m_timer
118