MONC
Functions/Subroutines | Variables
terminationcheck_mod Module Reference

This component will check for termination conditions at stages of the model run and terminate that specific stage if the parameters have been met. More...

Functions/Subroutines

type(component_descriptor_type) function, public terminationcheck_get_descriptor ()
 Provides the descriptor back to the caller and is used in component registration. More...
 
subroutine init_callback (current_state)
 Called upon model initialisation. Will basically read from the options database and set options in the database that are appropriate. More...
 
subroutine timestep_callback (current_state)
 Timestep hook which is called at each timestep to determine whether or not to terminate timestep iterations. More...
 
integer function check_messages_file (current_state)
 Checks the messages file for commands which determine user control of the model. More...
 

Variables

integer, parameter file_line_len =100
 
integer, parameter file_unit =10
 
integer max_timesteps
 
integer check_messages_file_frequency
 
integer check_walltime_frequency
 
integer max_walltime_secs
 
real(kind=default_precision) termination_time
 
character(len=string_length) messages_file_name
 
logical check_for_walltime
 

Detailed Description

This component will check for termination conditions at stages of the model run and terminate that specific stage if the parameters have been met.

Function/Subroutine Documentation

◆ check_messages_file()

integer function terminationcheck_mod::check_messages_file ( type(model_state_type), intent(inout), target  current_state)
private

Checks the messages file for commands which determine user control of the model.

Parameters
current_stateThe current model state

Definition at line 129 of file terminationcheck.F90.

129  type(model_state_type), target, intent(inout) :: current_state
130 
131  character(len=FILE_LINE_LEN) :: msg_line
132  integer :: ierr
133 
134  check_messages_file=0
135  open (unit=file_unit, file=messages_file_name, status='OLD', iostat=ierr)
136  if (ierr == 0) then
137  read(file_unit,"(A)",iostat=ierr) msg_line
138  if (ierr == 0) then
139  if (trim(msg_line) .eq. "terminate") then
140  check_messages_file=1
141  current_state%continue_timestep=.false.
142  end if
143  end if
144  end if
145  close(file_unit)
Here is the caller graph for this function:

◆ init_callback()

subroutine terminationcheck_mod::init_callback ( type(model_state_type), intent(inout), target  current_state)
private

Called upon model initialisation. Will basically read from the options database and set options in the database that are appropriate.

Parameters
current_stateThe current model state_mod

Definition at line 41 of file terminationcheck.F90.

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
44  logical :: mangled
45 
46  max_timesteps=options_get_integer(current_state%options_database, "nn_timesteps")
47  termination_time=options_get_real(current_state%options_database, "termination_time")
48  check_messages_file_frequency=options_get_integer(current_state%options_database, "check_msg_frequency")
49  messages_file_name=options_get_string(current_state%options_database, "msg_filename")
50  check_walltime_frequency=options_get_integer(current_state%options_database, "check_walltime_frequency")
51  walltime_string=options_get_string(current_state%options_database, "walltime_limit")
52  check_for_walltime=trim(walltime_string) /= "none"
53  if (check_for_walltime) then
54  pidx=1
55  mangled=.false.
56  do i=1, 2
57  idx=index(walltime_string(pidx:), ":")
58  if (idx .gt. 0) then
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))
61  pidx=pidx+idx
62  else
63  call log_master_log(log_warn, "Walltime limit of `"//trim(walltime_string)//&
64  "` does not contains hh:mm:ss, defaulting to no limit")
65  check_for_walltime=.false.
66  exit
67  end if
68  end do
69  if (check_for_walltime) then
70  walltime_secs=conv_to_integer(walltime_string(pidx:))
71  if (walltime_mins .lt. 0 .or. walltime_mins .gt. 59) then
72  walltime_mins=0
73  mangled=.true.
74  end if
75  if (walltime_secs .lt. 0 .or. walltime_secs .gt. 59) then
76  walltime_secs=0
77  mangled=.true.
78  end if
79  if (mangled) 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)))
83  end if
84  max_walltime_secs=(walltime_hours*60*60)+(walltime_mins*60)+walltime_secs
85  end if
86  end if
Here is the caller graph for this function:

◆ terminationcheck_get_descriptor()

type(component_descriptor_type) function, public terminationcheck_mod::terminationcheck_get_descriptor ( )

Provides the descriptor back to the caller and is used in component registration.

Returns
The termination check component descriptor

Definition at line 31 of file terminationcheck.F90.

31  terminationcheck_get_descriptor%name="termination_check"
32  terminationcheck_get_descriptor%version=0.1
33  terminationcheck_get_descriptor%initialisation=>init_callback
34  terminationcheck_get_descriptor%timestep=>timestep_callback
Here is the call graph for this function:

◆ timestep_callback()

subroutine terminationcheck_mod::timestep_callback ( type(model_state_type), intent(inout), target  current_state)
private

Timestep hook which is called at each timestep to determine whether or not to terminate timestep iterations.

Parameters
current_stateThe current model state_mod

Definition at line 92 of file terminationcheck.F90.

92  type(model_state_type), target, intent(inout) :: current_state
93 
94  integer :: ierr, file_message_status
95 
96  if (max_timesteps .gt. 0) then
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
99  else
100  current_state%continue_timestep=.true.
101  end if
102  if (current_state%continue_timestep) then
103  current_state%continue_timestep = current_state%time .lt. termination_time
104  if (.not. current_state%continue_timestep) current_state%termination_reason=time_termination_reason
105  end if
106  if (current_state%continue_timestep .and. check_for_walltime .and. &
107  mod(current_state%timestep, check_walltime_frequency) == 0) then
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
112  end if
113 
114  if (current_state%continue_timestep .and. mod(current_state%timestep, check_messages_file_frequency) == 0) then
115  if (current_state%parallel%my_rank == 0) then
116  file_message_status=check_messages_file(current_state)
117  call mpi_bcast(file_message_status, 1, mpi_int, 0, current_state%parallel%monc_communicator, ierr)
118  else
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.
121  end if
122  if (.not. current_state%continue_timestep) current_state%termination_reason=message_termination_reason
123  end if
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ check_for_walltime

logical terminationcheck_mod::check_for_walltime
private

Definition at line 22 of file terminationcheck.F90.

22  logical :: check_for_walltime

◆ check_messages_file_frequency

integer terminationcheck_mod::check_messages_file_frequency
private

Definition at line 19 of file terminationcheck.F90.

◆ check_walltime_frequency

integer terminationcheck_mod::check_walltime_frequency
private

Definition at line 19 of file terminationcheck.F90.

◆ file_line_len

integer, parameter terminationcheck_mod::file_line_len =100
private

Definition at line 18 of file terminationcheck.F90.

18  integer, parameter :: file_line_len=100, file_unit=10

◆ file_unit

integer, parameter terminationcheck_mod::file_unit =10
private

Definition at line 18 of file terminationcheck.F90.

◆ max_timesteps

integer terminationcheck_mod::max_timesteps
private

Definition at line 19 of file terminationcheck.F90.

19  integer :: max_timesteps, check_messages_file_frequency, check_walltime_frequency, max_walltime_secs

◆ max_walltime_secs

integer terminationcheck_mod::max_walltime_secs
private

Definition at line 19 of file terminationcheck.F90.

◆ messages_file_name

character(len=string_length) terminationcheck_mod::messages_file_name
private

Definition at line 21 of file terminationcheck.F90.

21  character(len=STRING_LENGTH) :: messages_file_name

◆ termination_time

real(kind=default_precision) terminationcheck_mod::termination_time
private

Definition at line 20 of file terminationcheck.F90.

20  real(kind=DEFAULT_PRECISION) :: termination_time