34 use mom_coms, only : sum_across_pes, pe_here, num_pes
36 use mom_io, only : open_file, append_file, ascii_file, writeonly_file
40 implicit none ;
private 55 type(time_type) :: start_time
57 real :: startup_cputime
58 real :: prev_cputime = 0.0
59 real :: dn_dcpu_min = -1.0
60 real :: cputime2 = 0.0
61 integer :: previous_calls = 0
63 integer :: filecpu_ascii
64 character(len=200) :: cpufile
73 integer :: new_cputime
74 if (.not.
associated(cs))
allocate(cs)
77 cs%prev_cputime = new_cputime
82 character(len=*),
intent(in) :: directory
83 type(time_type),
intent(in) :: Input_start_time
91 integer :: new_cputime
93 #include "version_variable.h" 94 character(len=40) :: mdl =
'MOM_write_cputime' 96 if (.not.
associated(cs))
then 99 cs%prev_cputime = new_cputime
104 call get_param(param_file, mdl,
"MAXCPU", cs%maxcpu, &
105 "The maximum amount of cpu time per processor for which \n"//&
106 "MOM should run before saving a restart file and \n"//&
107 "quitting with a return value that indicates that a \n"//&
108 "further run is required to complete the simulation. \n"//&
109 "If automatic restarts are not desired, use a negative \n"//&
110 "value for MAXCPU. MAXCPU has units of wall-clock \n"//&
111 "seconds, so the actual CPU time used is larger by a \n"//&
112 "factor of the number of processors used.", &
113 units=
"wall-clock seconds", default=-1.0)
114 call get_param(param_file, mdl,
"CPU_TIME_FILE", cs%CPUfile, &
115 "The file into which CPU time is written.",default=
"CPU_stats")
116 cs%CPUfile = trim(directory)//trim(cs%CPUfile)
117 call log_param(param_file, mdl,
"directory/CPU_TIME_FILE", cs%CPUfile)
119 cs%CPUfile = trim(cs%CPUfile)//
"."//trim(adjustl(statslabel))
122 cs%Start_time = input_start_time
127 type(time_type),
intent(inout) :: day
128 integer,
intent(in) :: n
129 integer,
intent(inout) :: nmax
144 integer :: new_cputime
146 integer :: start_of_day, num_days
148 if (.not.
associated(cs))
call mom_error(fatal, &
149 "write_energy: Module must be initialized before it is used.")
158 d_cputime = new_cputime - cs%prev_cputime +
max_ticks 160 d_cputime = new_cputime - cs%prev_cputime
163 call sum_across_pes(d_cputime)
164 if (cs%previous_calls == 0) cs%startup_cputime = d_cputime
166 cs%cputime2 = cs%cputime2 + d_cputime
168 if ((cs%previous_calls >= 1) .and. (cs%maxcpu > 0.0))
then 170 if ((n > cs%prev_n) .and. (d_cputime > 0.0) .and. &
171 ((cs%dn_dcpu_min*d_cputime < (n - cs%prev_n)) .or. &
172 (cs%dn_dcpu_min < 0.0))) &
173 cs%dn_dcpu_min = (n - cs%prev_n) / d_cputime
174 if (cs%dn_dcpu_min >= 0.0)
then 176 nmax = n + int( cs%dn_dcpu_min * &
177 (0.95*cs%maxcpu *
REAL(num_pes())*CLOCKS_PER_SEC - &
178 (cs%startup_cputime + cs%cputime2)) )
184 cs%prev_cputime = new_cputime ; cs%prev_n = n
186 call get_time(day, start_of_day, num_days)
187 reday =
REAL(num_days)+ (
REAL(start_of_day)/86400.0)
190 if ((cs%previous_calls == 0) .and. (
is_root_pe()))
then 191 if (day > cs%Start_time)
then 192 call open_file(cs%fileCPU_ascii, trim(cs%CPUfile), &
193 action=append_file, form=ascii_file, nohdrs=.true.)
195 call open_file(cs%fileCPU_ascii, trim(cs%CPUfile), &
196 action=writeonly_file, form=ascii_file, nohdrs=.true.)
201 if (cs%previous_calls == 0)
then 202 write(cs%fileCPU_ascii, &
203 '("Startup CPU time: ", F12.3, " sec summed across", I5, " PEs.")') &
204 (cs%startup_cputime / clocks_per_sec), num_pes()
205 write(cs%fileCPU_ascii,*)
" Day, Step number, CPU time, CPU time change" 207 write(cs%fileCPU_ascii,
'(F12.3,", "I11,", ", F12.3,", ", F12.3)') &
208 reday, n, (cs%cputime2 /
real(clocks_per_sec)), &
209 d_cputime /
real(clocks_per_sec)
211 cs%previous_calls = cs%previous_calls + 1
subroutine, public write_cputime_start_clock(CS)
subroutine, public mom_write_cputime_init(param_file, directory, Input_start_time, CS)
subroutine, public write_cputime(day, n, nmax, CS)
This module contains I/O framework code.
logical function, public is_root_pe()
subroutine, public mom_error(level, message, all_print)