11 use mpi
, only : mpi_int, mpi_logical, mpi_in_place, mpi_lor, mpi_wtime
41 type(model_state_type),
target,
intent(inout) :: current_state
42 integer :: i, idx, pidx, walltime_secs, walltime_mins, walltime_hours
43 character(len=STRING_LENGTH) :: walltime_string
46 max_timesteps=options_get_integer(current_state%options_database,
"nn_timesteps")
47 termination_time=options_get_real(current_state%options_database,
"termination_time")
51 walltime_string=options_get_string(current_state%options_database,
"walltime_limit")
57 idx=index(walltime_string(pidx:),
":")
59 if (i==1) walltime_hours=conv_to_integer(walltime_string(pidx:pidx+idx-2))
60 if (i==2) walltime_mins=conv_to_integer(walltime_string(pidx:pidx+idx-2))
63 call log_master_log(log_warn,
"Walltime limit of `"//trim(walltime_string)//&
64 "` does not contains hh:mm:ss, defaulting to no limit")
70 walltime_secs=conv_to_integer(walltime_string(pidx:))
71 if (walltime_mins .lt. 0 .or. walltime_mins .gt. 59)
then 75 if (walltime_secs .lt. 0 .or. walltime_secs .gt. 59)
then 80 call log_master_log(log_warn,
"Walltime limit of `"//trim(walltime_string)//
"` mangled, defaulting to "//&
81 trim(conv_to_string(walltime_hours))//
":"//trim(conv_to_string(walltime_mins))//
":"//&
82 trim(conv_to_string(walltime_secs)))
92 type(model_state_type),
target,
intent(inout) :: current_state
94 integer :: ierr, file_message_status
97 current_state%continue_timestep=mod(current_state%timestep,
max_timesteps) /= 0
98 if (.not. current_state%continue_timestep) current_state%termination_reason=timestep_termination_reason
100 current_state%continue_timestep=.true.
102 if (current_state%continue_timestep)
then 104 if (.not. current_state%continue_timestep) current_state%termination_reason=time_termination_reason
108 current_state%continue_timestep=int(mpi_wtime() - current_state%model_start_wtime) .lt.
max_walltime_secs 109 call mpi_allreduce(mpi_in_place, current_state%continue_timestep, 1, mpi_logical, mpi_lor, &
110 current_state%parallel%monc_communicator, ierr)
111 if (.not. current_state%continue_timestep) current_state%termination_reason=walltime_termination_reason
115 if (current_state%parallel%my_rank == 0)
then 117 call mpi_bcast(file_message_status, 1, mpi_int, 0, current_state%parallel%monc_communicator, ierr)
119 call mpi_bcast(file_message_status, 1, mpi_int, 0, current_state%parallel%monc_communicator, ierr)
120 if (file_message_status == 1) current_state%continue_timestep=.false.
122 if (.not. current_state%continue_timestep) current_state%termination_reason=message_termination_reason
129 type(model_state_type),
target,
intent(inout) :: current_state
131 character(len=FILE_LINE_LEN) :: msg_line
137 read(
file_unit,
"(A)",iostat=ierr) msg_line
139 if (trim(msg_line) .eq.
"terminate")
then 141 current_state%continue_timestep=.false.
Generic add interface for adding different types of data to the databases.
logical check_for_walltime
integer max_walltime_secs
integer function check_messages_file(current_state)
Checks the messages file for commands which determine user control of the model.
character(len=string_length) messages_file_name
integer, parameter, public message_termination_reason
character(len=string_length) function, public options_get_string(options_database, key, index)
Retrieves a string value from the database that matches the provided key.
integer, parameter, public default_precision
MPI communication type which we use for the prognostic and calculation data.
real(kind=default_precision) termination_time
Contains common definitions for the data and datatypes used by MONC.
The ModelState which represents the current state of a run.
This component will check for termination conditions at stages of the model run and terminate that sp...
subroutine, public log_master_log(level, message)
Will log just from the master process.
Conversion between common inbuilt FORTRAN data types.
Converts data types to strings.
Description of a component.
subroutine timestep_callback(current_state)
Timestep hook which is called at each timestep to determine whether or not to terminate timestep iter...
integer, parameter, public timestep_termination_reason
Interfaces and types that MONC components must specify.
integer check_messages_file_frequency
integer, parameter, public time_termination_reason
The constants defining the reason why the model has terminated.
integer, parameter, public log_warn
Log WARNING and ERROR messages.
integer, parameter, public string_length
Default length of strings.
real(kind=default_precision) function, public options_get_real(options_database, key, index)
Retrieves a real value from the database that matches the provided key.
integer function, public options_get_integer(options_database, key, index)
Retrieves an integer value from the database that matches the provided key.
Manages the options database. Contains administration functions and deduce runtime options from the c...
integer, parameter file_line_len
integer, parameter, public walltime_termination_reason
Converts data types to integers.
integer, parameter file_unit
logical function, public options_has_key(options_database, key)
Determines whether a specific key is in the database.
The model state which represents the current state of a run.
type(component_descriptor_type) function, public terminationcheck_get_descriptor()
Provides the descriptor back to the caller and is used in component registration. ...
integer check_walltime_frequency
real(kind=double_precision) function, public conv_single_real_to_double(input_real)
Converts from a single to double precision real. This applies some rounding to a certain number of de...
subroutine init_callback(current_state)
Called upon model initialisation. Will basically read from the options database and set options in th...