-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclocks.f90
124 lines (82 loc) · 3.25 KB
/
clocks.f90
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
module clocks
use precision, only: dp
use file_admin, only: log_unit
use my_mpi, only: rank
implicit none
! Start and end time for CPU report
real :: cputime1 !< Start time for CPU report
real :: cputime2 !< End time for CPU report
real(kind=dp) :: cpu_seconds=0.0
integer :: cpu_hours=0
integer :: cpu_minutes=0
! Wall clock time variables
integer :: cntr1 !< Start time wall clock
integer :: cntr2 !< End time wall clock
integer :: countspersec !< counts per second (for wall clock time)
real(kind=dp) :: clock_seconds=0.0
integer :: clock_hours=0
integer :: clock_minutes=0
contains
!=======================================================================
subroutine setup_clocks
call setup_cpuclock()
call setup_wallclock()
end subroutine setup_clocks
!=======================================================================
subroutine setup_cpuclock
! Initialize cpu timer
call cpu_time(cputime1)
end subroutine setup_cpuclock
!=======================================================================
subroutine setup_wallclock
! Initialize wall cock timer
call system_clock(cntr1)
end subroutine setup_wallclock
!=======================================================================
subroutine update_clocks
call update_cpuclock
call update_wallclock
end subroutine update_clocks
!=======================================================================
subroutine update_cpuclock
! Find out intermediate CPU time (to avoid overflowing the counter)
call cpu_time(cputime2)
cpu_seconds=cpu_seconds+real(cputime2-cputime1)
cputime1=cputime2
cpu_minutes = cpu_minutes + int(cpu_seconds) / 60
cpu_seconds = MOD ( cpu_seconds , 60.0 )
cpu_hours = cpu_hours + cpu_minutes / 60
cpu_minutes = MOD ( cpu_minutes , 60 )
end subroutine update_cpuclock
!=======================================================================
subroutine update_wallclock
call system_clock(cntr2,countspersec)
clock_seconds=clock_seconds+real(cntr2-cntr1)/real(countspersec)
cntr1=cntr2
clock_minutes = clock_minutes + int(clock_seconds) / 60
clock_seconds = MOD ( clock_seconds , 60.0 )
clock_hours = clock_hours + clock_minutes / 60
clock_minutes = MOD ( clock_minutes , 60 )
end subroutine update_wallclock
!=======================================================================
subroutine report_clocks
call report_cpuclock
call report_wallclock
end subroutine report_clocks
!=======================================================================
subroutine report_cpuclock
call update_cpuclock ()
if (rank == 0) then
write(log_unit,*) "CPU time: ",cpu_hours,' hours',cpu_minutes,' minutes', &
cpu_seconds,' seconds.'
endif
end subroutine report_cpuclock
!=======================================================================
subroutine report_wallclock
call update_wallclock ()
if (rank == 0) then
write(log_unit,*) "Wall clock time: ",clock_hours,' hours', &
clock_minutes,' minutes',clock_seconds,' seconds.'
endif
end subroutine report_wallclock
end module clocks