MOM6
mom_write_cputime Module Reference

Detailed Description

A module to monitor the overall CPU time used by MOM6 and project when to stop the model.

By Robert Hallberg, May 2006.

This file contains the subroutine (write_cputime) that writes the summed CPU time across all processors to an output file. In addition, write_cputime estimates how many more time steps can be taken before 95% of the available CPU time is used, so that the model can be checkpointed at that time.

Data Types

type  write_cputime_cs
 A control structure that regulates the writing of CPU time. More...
 

Functions/Subroutines

subroutine, public write_cputime_start_clock (CS)
 Evaluate the CPU time returned by SYSTEM_CLOCK at the start of a run. More...
 
subroutine, public mom_write_cputime_init (param_file, directory, Input_start_time, CS)
 Initialize the MOM_write_cputime module. More...
 
subroutine, public write_cputime (day, n, nmax, CS)
 This subroutine assesses how much CPU time the model has taken and determines how long the model should be run before it saves a restart file and stops itself. More...
 

Variables

integer clocks_per_sec = 1000
 The number of clock cycles per second, used by the system clock. More...
 
integer max_ticks = 1000
 The number of ticks per second, used by the system clock. More...
 

Function/Subroutine Documentation

◆ mom_write_cputime_init()

subroutine, public mom_write_cputime::mom_write_cputime_init ( type(param_file_type), intent(in)  param_file,
character(len=*), intent(in)  directory,
type(time_type), intent(in)  Input_start_time,
type(write_cputime_cs), pointer  CS 
)

Initialize the MOM_write_cputime module.

Parameters
[in]param_fileA structure to parse for run-time parameters
[in]directoryThe directory where the CPU time file goes.
[in]input_start_timeThe start model time of the simulation.
csA pointer that may be set to point to the control structure for this module.

Definition at line 55 of file MOM_write_cputime.F90.

55  type(param_file_type), intent(in) :: param_file !< A structure to parse for run-time parameters
56  character(len=*), intent(in) :: directory !< The directory where the CPU time file goes.
57  type(time_type), intent(in) :: Input_start_time !< The start model time of the simulation.
58  type(write_cputime_CS), pointer :: CS !< A pointer that may be set to point to the
59  !! control structure for this module.
60 
61  ! Local variables
62  integer :: new_cputime ! The CPU time returned by SYSTEM_CLOCK
63 ! This include declares and sets the variable "version".
64 #include "version_variable.h"
65  character(len=40) :: mdl = 'MOM_write_cputime' ! This module's name.
66 
67  if (.not.associated(cs)) then
68  allocate(cs)
69  call system_clock(new_cputime, clocks_per_sec, max_ticks)
70  cs%prev_cputime = new_cputime
71  endif
72 
73  ! Read all relevant parameters and write them to the model log.
74  call log_version(param_file, mdl, version, "")
75  call get_param(param_file, mdl, "MAXCPU", cs%maxcpu, &
76  "The maximum amount of cpu time per processor for which "//&
77  "MOM should run before saving a restart file and "//&
78  "quitting with a return value that indicates that a "//&
79  "further run is required to complete the simulation. "//&
80  "If automatic restarts are not desired, use a negative "//&
81  "value for MAXCPU. MAXCPU has units of wall-clock "//&
82  "seconds, so the actual CPU time used is larger by a "//&
83  "factor of the number of processors used.", &
84  units="wall-clock seconds", default=-1.0)
85  call get_param(param_file, mdl, "CPU_TIME_FILE", cs%CPUfile, &
86  "The file into which CPU time is written.",default="CPU_stats")
87  cs%CPUfile = trim(directory)//trim(cs%CPUfile)
88  call log_param(param_file, mdl, "directory/CPU_TIME_FILE", cs%CPUfile)
89 #ifdef STATSLABEL
90  cs%CPUfile = trim(cs%CPUfile)//"."//trim(adjustl(statslabel))
91 #endif
92 
93  cs%Start_time = input_start_time
94 

References clocks_per_sec, and max_ticks.

Referenced by mom_main().

Here is the caller graph for this function:

◆ write_cputime()

subroutine, public mom_write_cputime::write_cputime ( type(time_type), intent(inout)  day,
integer, intent(in)  n,
integer, intent(inout)  nmax,
type(write_cputime_cs), pointer  CS 
)

This subroutine assesses how much CPU time the model has taken and determines how long the model should be run before it saves a restart file and stops itself.

Parameters
[in,out]dayThe current model time.
[in]nThe time step number of the current execution.
[in,out]nmaxThe number of iterations after which to stop so that the simulation will not run out of CPU time.
csThe control structure set up by a previous call to MOM_write_cputime_init.

Definition at line 100 of file MOM_write_cputime.F90.

100  type(time_type), intent(inout) :: day !< The current model time.
101  integer, intent(in) :: n !< The time step number of the current execution.
102  integer, intent(inout) :: nmax !< The number of iterations after which to stop so
103  !! that the simulation will not run out of CPU time.
104  type(write_cputime_CS), pointer :: CS !< The control structure set up by a previous
105  !! call to MOM_write_cputime_init.
106 
107  ! Local variables
108  real :: d_cputime ! The change in CPU time since the last call
109  ! this subroutine.
110  integer :: new_cputime ! The CPU time returned by SYSTEM_CLOCK
111  real :: reday ! A real version of day.
112  character(len=256) :: mesg ! The text of an error message
113  integer :: start_of_day, num_days
114 
115  if (.not.associated(cs)) call mom_error(fatal, &
116  "write_energy: Module must be initialized before it is used.")
117 
118  call system_clock(new_cputime, clocks_per_sec, max_ticks)
119 ! The following lines extract useful information even if the clock has rolled
120 ! over, assuming a 32-bit SYSTEM_CLOCK. With more bits, rollover is essentially
121 ! impossible. Negative fluctuations of less than 10 seconds are not interpreted
122 ! as the clock rolling over. This should be unnecessary but is sometimes needed
123 ! on the GFDL SGI/O3k.
124  if (new_cputime < cs%prev_cputime-(10.0*clocks_per_sec)) then
125  d_cputime = new_cputime - cs%prev_cputime + max_ticks
126  else
127  d_cputime = new_cputime - cs%prev_cputime
128  endif
129 
130  call sum_across_pes(d_cputime)
131  if (cs%previous_calls == 0) cs%startup_cputime = d_cputime
132 
133  cs%cputime2 = cs%cputime2 + d_cputime
134 
135  if ((cs%previous_calls >= 1) .and. (cs%maxcpu > 0.0)) then
136  ! Determine the slowest rate at which time steps are executed.
137  if ((n > cs%prev_n) .and. (d_cputime > 0.0) .and. &
138  ((cs%dn_dcpu_min*d_cputime < (n - cs%prev_n)) .or. &
139  (cs%dn_dcpu_min < 0.0))) &
140  cs%dn_dcpu_min = (n - cs%prev_n) / d_cputime
141  if (cs%dn_dcpu_min >= 0.0) then
142  ! Have the model stop itself after 95% of the CPU time has been used.
143  nmax = n + int( cs%dn_dcpu_min * &
144  (0.95*cs%maxcpu * real(num_pes())*clocks_per_sec - &
145  (cs%startup_cputime + cs%cputime2)) )
146 ! write(mesg,*) "Resetting nmax to ",nmax," at day",reday
147 ! call MOM_mesg(mesg)
148  endif
149  endif
150  cs%prev_cputime = new_cputime ; cs%prev_n = n
151 
152  call get_time(day, start_of_day, num_days)
153  reday = real(num_days)+ (real(start_of_day)/86400.0)
154 
155  ! Reopen or create a text output file.
156  if ((cs%previous_calls == 0) .and. (is_root_pe())) then
157  if (day > cs%Start_time) then
158  call open_file(cs%fileCPU_ascii, trim(cs%CPUfile), &
159  action=append_file, form=ascii_file, nohdrs=.true.)
160  else
161  call open_file(cs%fileCPU_ascii, trim(cs%CPUfile), &
162  action=writeonly_file, form=ascii_file, nohdrs=.true.)
163  endif
164  endif
165 
166  if (is_root_pe()) then
167  if (cs%previous_calls == 0) then
168  write(cs%fileCPU_ascii, &
169  '("Startup CPU time: ", F12.3, " sec summed across", I5, " PEs.")') &
170  (cs%startup_cputime / clocks_per_sec), num_pes()
171  write(cs%fileCPU_ascii,*)" Day, Step number, CPU time, CPU time change"
172  endif
173  write(cs%fileCPU_ascii,'(F12.3,", "I11,", ", F12.3,", ", F12.3)') &
174  reday, n, (cs%cputime2 / real(clocks_per_sec)), &
175  d_cputime / real(clocks_per_sec)
176  endif
177  cs%previous_calls = cs%previous_calls + 1
178 

References clocks_per_sec, mom_error_handler::is_root_pe(), max_ticks, and mom_error_handler::mom_error().

Referenced by mom_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_cputime_start_clock()

subroutine, public mom_write_cputime::write_cputime_start_clock ( type(write_cputime_cs), pointer  CS)

Evaluate the CPU time returned by SYSTEM_CLOCK at the start of a run.

Parameters
csThe control structure set up by a previous call to MOM_write_cputime_init.

Definition at line 44 of file MOM_write_cputime.F90.

44  type(write_cputime_CS), pointer :: CS !< The control structure set up by a previous
45  !! call to MOM_write_cputime_init.
46  integer :: new_cputime ! The CPU time returned by SYSTEM_CLOCK
47  if (.not.associated(cs)) allocate(cs)
48 
49  call system_clock(new_cputime, clocks_per_sec, max_ticks)
50  cs%prev_cputime = new_cputime

References clocks_per_sec, and max_ticks.

Referenced by mom_main().

Here is the caller graph for this function:

Variable Documentation

◆ clocks_per_sec

integer mom_write_cputime::clocks_per_sec = 1000
private

The number of clock cycles per second, used by the system clock.

Definition at line 18 of file MOM_write_cputime.F90.

18 integer :: CLOCKS_PER_SEC = 1000 !< The number of clock cycles per second, used by the system clock

Referenced by mom_write_cputime_init(), write_cputime(), and write_cputime_start_clock().

◆ max_ticks

integer mom_write_cputime::max_ticks = 1000
private

The number of ticks per second, used by the system clock.

Definition at line 19 of file MOM_write_cputime.F90.

19 integer :: MAX_TICKS = 1000 !< The number of ticks per second, used by the system clock

Referenced by mom_write_cputime_init(), write_cputime(), and write_cputime_start_clock().