6 use mom_coms, only : sum_across_pes, num_pes
8 use mom_io, only : open_file, close_file, append_file, ascii_file, writeonly_file
12 implicit none ;
private 14 public write_cputime, mom_write_cputime_init, mom_write_cputime_end, write_cputime_start_clock
18 integer :: clocks_per_sec = 1000
19 integer :: max_ticks = 1000
28 type(time_type) :: start_time
30 real :: startup_cputime
31 real :: prev_cputime = 0.0
32 real :: dn_dcpu_min = -1.0
33 real :: cputime2 = 0.0
34 integer :: previous_calls = 0
36 integer :: filecpu_ascii= -1
37 character(len=200) :: cpufile
43 subroutine write_cputime_start_clock(CS)
46 integer :: new_cputime
47 if (.not.
associated(cs))
allocate(cs)
49 call system_clock(new_cputime, clocks_per_sec, max_ticks)
50 cs%prev_cputime = new_cputime
51 end subroutine write_cputime_start_clock
54 subroutine mom_write_cputime_init(param_file, directory, Input_start_time, CS)
56 character(len=*),
intent(in) :: directory
57 type(time_type),
intent(in) :: Input_start_time
62 integer :: new_cputime
64 # include "version_variable.h" 65 character(len=40) :: mdl =
'MOM_write_cputime' 66 logical :: all_default
68 if (.not.
associated(cs))
then 70 call system_clock(new_cputime, clocks_per_sec, max_ticks)
71 cs%prev_cputime = new_cputime
77 call get_param(param_file, mdl,
"MAXCPU", cs%maxcpu, default=-1.0, do_not_log=.true.)
78 call get_param(param_file, mdl,
"CPU_TIME_FILE", cs%CPUfile, default=
"CPU_stats", do_not_log=.true.)
79 all_default = (cs%maxcpu == -1.0) .and. (trim(cs%CPUfile) == trim(
"CPU_stats"))
81 call log_version(param_file, mdl, version,
"", all_default=all_default)
82 call get_param(param_file, mdl,
"MAXCPU", cs%maxcpu, &
83 "The maximum amount of cpu time per processor for which "//&
84 "MOM should run before saving a restart file and "//&
85 "quitting with a return value that indicates that a "//&
86 "further run is required to complete the simulation. "//&
87 "If automatic restarts are not desired, use a negative "//&
88 "value for MAXCPU. MAXCPU has units of wall-clock "//&
89 "seconds, so the actual CPU time used is larger by a "//&
90 "factor of the number of processors used.", &
91 units=
"wall-clock seconds", default=-1.0)
92 call get_param(param_file, mdl,
"CPU_TIME_FILE", cs%CPUfile, &
93 "The file into which CPU time is written.",default=
"CPU_stats")
94 cs%CPUfile = trim(directory)//trim(cs%CPUfile)
95 call log_param(param_file, mdl,
"directory/CPU_TIME_FILE", cs%CPUfile)
97 cs%CPUfile = trim(cs%CPUfile)//
"."//trim(adjustl(statslabel))
100 cs%Start_time = input_start_time
102 end subroutine mom_write_cputime_init
105 subroutine mom_write_cputime_end(CS)
109 if (.not.
associated(cs))
return 112 if (is_root_pe() .and. cs%fileCPU_ascii > 0)
then 113 call flush(cs%fileCPU_ascii)
114 call close_file(cs%fileCPU_ascii)
119 end subroutine mom_write_cputime_end
124 subroutine write_cputime(day, n, CS, nmax, call_end)
125 type(time_type),
intent(inout) :: day
126 integer,
intent(in) :: n
129 integer,
optional,
intent(inout) :: nmax
131 logical,
optional,
intent(in) :: call_end
136 integer :: new_cputime
138 character(len=256) :: mesg
139 integer :: start_of_day, num_days
141 if (.not.
associated(cs))
call mom_error(fatal, &
142 "write_energy: Module must be initialized before it is used.")
144 call system_clock(new_cputime, clocks_per_sec, max_ticks)
150 if (new_cputime < cs%prev_cputime-(10.0*clocks_per_sec))
then 151 d_cputime = new_cputime - cs%prev_cputime + max_ticks
153 d_cputime = new_cputime - cs%prev_cputime
156 call sum_across_pes(d_cputime)
157 if (cs%previous_calls == 0) cs%startup_cputime = d_cputime
159 cs%cputime2 = cs%cputime2 + d_cputime
161 if ((cs%previous_calls >= 1) .and. (cs%maxcpu > 0.0))
then 163 if ((n > cs%prev_n) .and. (d_cputime > 0.0) .and. &
164 ((cs%dn_dcpu_min*d_cputime < (n - cs%prev_n)) .or. &
165 (cs%dn_dcpu_min < 0.0))) &
166 cs%dn_dcpu_min = (n - cs%prev_n) / d_cputime
167 if (
present(nmax) .and. (cs%dn_dcpu_min >= 0.0))
then 169 nmax = n + int( cs%dn_dcpu_min * &
170 (0.95*cs%maxcpu *
REAL(num_pes())*CLOCKS_PER_SEC - &
171 (cs%startup_cputime + cs%cputime2)) )
176 cs%prev_cputime = new_cputime ; cs%prev_n = n
178 call get_time(day, start_of_day, num_days)
179 reday =
REAL(num_days)+ (
REAL(start_of_day)/86400.0)
182 if ((cs%previous_calls == 0) .and. (is_root_pe()))
then 183 if (day > cs%Start_time)
then 184 call open_file(cs%fileCPU_ascii, trim(cs%CPUfile), &
185 action=append_file, form=ascii_file, nohdrs=.true.)
187 call open_file(cs%fileCPU_ascii, trim(cs%CPUfile), &
188 action=writeonly_file, form=ascii_file, nohdrs=.true.)
192 if (is_root_pe())
then 193 if (cs%previous_calls == 0)
then 194 write(cs%fileCPU_ascii, &
195 '("Startup CPU time: ", F12.3, " sec summed across", I5, " PEs.")') &
196 (cs%startup_cputime / clocks_per_sec), num_pes()
197 write(cs%fileCPU_ascii,*)
" Day, Step number, CPU time, CPU time change" 199 write(cs%fileCPU_ascii,
'(F12.3,", "I11,", ", F12.3,", ", F12.3)') &
200 reday, n, (cs%cputime2 /
real(clocks_per_sec)), &
201 d_cputime /
real(clocks_per_sec)
203 call flush(cs%fileCPU_ascii)
205 cs%previous_calls = cs%previous_calls + 1
207 if (
present(call_end))
then 208 if (call_end)
call mom_write_cputime_end(cs)
211 end subroutine write_cputime
Wraps the FMS time manager functions.
A control structure that regulates the writing of CPU time.
A structure that can be parsed to read and document run-time parameters.
A module to monitor the overall CPU time used by MOM6 and project when to stop the model...
This module contains I/O framework code.
The MOM6 facility to parse input files for runtime parameters.
An overloaded interface to log the values of various types of parameters.
Interfaces to non-domain-oriented communication subroutines, including the MOM6 reproducing sums faci...
Routines for error handling and I/O management.
An overloaded interface to log version information about modules.
An overloaded interface to read and log the values of various types of parameters.