1
+ ! >
2
+ ! ! \brief This module contains variables and routines for dealing with
3
+ ! ! cpu and wall clocks
4
+ ! !
5
+ ! ! This module uses calls to the Fortran 2003 internal routines cpu_time
6
+ ! ! and system_clock. To get the time passed between two events, one has
7
+ ! ! to call these twice, once at the start and once at the end.
8
+ ! ! To avoid overflowing the variable (which can happen for codes that run
9
+ ! ! for many hours or days), this module provides "update" routines that
10
+ ! ! update hour and minute counters. These should be called at regular
11
+ ! ! intervals. The module also comes with its own reporting routines.
12
+ ! !
13
+ ! ! General module
14
+ ! !
15
+ ! ! Dependencies:
16
+ ! ! - file_admin module (for the unit of the log file where to write the report)
17
+ ! ! - my_mpi (for the value of rank, the MPI id of the current processor, reporting is only done for the rank 0 processor)
18
+ ! !
19
+ ! ! Author: Garrelt Mellema
20
+ ! !
21
+ ! ! Date: 2010-03-08
22
+ ! !
23
+ ! ! Version: 1.0
24
+ ! !
25
+ ! <
26
+
1
27
module clocks
2
28
3
- use precision, only: dp
4
29
use file_admin, only: logf
5
30
use my_mpi, only: rank
6
31
7
32
implicit none
8
33
9
34
! Start and end time for CPU report
10
- real :: cputime1 ! < Start time for CPU report
11
- real :: cputime2 ! < End time for CPU report
12
- real (kind= dp) :: cpu_seconds= 0.0
13
- integer :: cpu_hours= 0
14
- integer :: cpu_minutes= 0
35
+ real :: cputime1 ! < Start time for call to CPU routine
36
+ real :: cputime2 ! < End time for call to CPU routine
37
+
38
+ integer :: cpu_hours= 0 ! < accumulates the CPU hours
39
+ integer :: cpu_minutes= 0 ! < accumulates the CPU minutes
40
+ real :: cpu_seconds= 0.0 ! < accumulates the CPU seconds
15
41
16
42
! Wall clock time variables
17
- integer :: cntr1 ! < Start time wall clock
18
- integer :: cntr2 ! < End time wall clock
43
+ integer :: cntr1 ! < Start time for call to wall clock routine
44
+ integer :: cntr2 ! < End time for call to wall clock routine
45
+
19
46
integer :: countspersec ! < counts per second (for wall clock time)
20
- real (kind= dp) :: clock_seconds= 0.0
21
- integer :: clock_hours= 0
22
- integer :: clock_minutes= 0
47
+
48
+ integer :: clock_hours= 0 ! < accumulates the wall clock hours
49
+ integer :: clock_minutes= 0 ! < accumulates the wall clock minutes
50
+ real :: clock_seconds= 0.0 ! < accumulates the wall clock seconds
23
51
24
52
contains
25
53
26
54
! =======================================================================
27
55
56
+ ! > Sets up all the clocks (initialization routine)
28
57
subroutine setup_clocks
29
58
30
59
call setup_cpuclock()
@@ -34,6 +63,7 @@ end subroutine setup_clocks
34
63
35
64
! =======================================================================
36
65
66
+ ! > Sets up cpu clock (initialization routine)
37
67
subroutine setup_cpuclock
38
68
39
69
! Initialize cpu timer
@@ -43,6 +73,7 @@ end subroutine setup_cpuclock
43
73
44
74
! =======================================================================
45
75
76
+ ! > Sets up wall clock (initialization routine)
46
77
subroutine setup_wallclock
47
78
48
79
! Initialize wall cock timer
@@ -52,6 +83,7 @@ end subroutine setup_wallclock
52
83
53
84
! =======================================================================
54
85
86
+ ! > Updates all the clocks
55
87
subroutine update_clocks
56
88
57
89
call update_cpuclock
@@ -61,6 +93,7 @@ end subroutine update_clocks
61
93
62
94
! =======================================================================
63
95
96
+ ! > Updates CPU clock
64
97
subroutine update_cpuclock
65
98
66
99
! Find out intermediate CPU time (to avoid overflowing the counter)
@@ -76,6 +109,7 @@ end subroutine update_cpuclock
76
109
77
110
! =======================================================================
78
111
112
+ ! > Updates wall clock
79
113
subroutine update_wallclock
80
114
81
115
call system_clock (cntr2,countspersec)
@@ -90,6 +124,7 @@ end subroutine update_wallclock
90
124
91
125
! =======================================================================
92
126
127
+ ! > Reports all the clocks
93
128
subroutine report_clocks
94
129
95
130
call report_cpuclock
@@ -99,6 +134,7 @@ end subroutine report_clocks
99
134
100
135
! =======================================================================
101
136
137
+ ! > Reports CPU clock to log file (unit logf)
102
138
subroutine report_cpuclock
103
139
104
140
call update_cpuclock ()
@@ -111,6 +147,7 @@ end subroutine report_cpuclock
111
147
112
148
! =======================================================================
113
149
150
+ ! > Reports wall clock to log file (unit logf)
114
151
subroutine report_wallclock
115
152
116
153
call update_wallclock ()
0 commit comments