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.