56 in_scf_energy_message_tag, in_exit_tag)
58 INTEGER,
INTENT(IN) :: in_external_master_id
59 INTEGER,
INTENT(IN),
OPTIONAL :: in_scf_energy_message_tag, in_exit_tag
61 cpassert(in_external_master_id >= 0)
64 external_master_id = in_external_master_id
66 IF (
PRESENT(in_scf_energy_message_tag))
THEN
67 scf_energy_message_tag = in_scf_energy_message_tag
69 IF (
PRESENT(in_exit_tag))
THEN
71 cpassert(in_exit_tag /= -1)
72 exit_tag = in_exit_tag
90 SUBROUTINE external_control(should_stop, flag, globenv, target_time, start_time, force_check)
92 LOGICAL,
INTENT(OUT) :: should_stop
93 CHARACTER(LEN=*),
INTENT(IN) :: flag
95 REAL(
dp),
OPTIONAL :: target_time, start_time
96 LOGICAL,
OPTIONAL :: force_check
98 CHARACTER(LEN=*),
PARAMETER :: routinen =
'external_control'
100 CHARACTER(LEN=default_string_length) :: exit_fname, exit_fname_level, &
101 exit_gname, exit_gname_level
102 INTEGER :: handle, i, tag, unit_number
103 LOGICAL :: should_wait
104 LOGICAL,
SAVE :: check_always = .false.
105 REAL(kind=
dp) :: my_start_time, my_target_time, t1, t2, &
107 REAL(kind=
dp),
SAVE :: t_last_file_check = 0.0_dp
110 CALL timeset(routinen, handle)
113 should_stop = .false.
115 IF (
PRESENT(force_check))
THEN
116 IF (force_check)
THEN
117 check_always = .true.
122 exit_gname_level = trim(exit_gname)//
"_"//trim(flag)
123 exit_fname = trim(logger%iter_info%project_name)//
"."//trim(exit_gname)
124 exit_fname_level = trim(logger%iter_info%project_name)//
"."//trim(exit_gname_level)
127 IF (exit_tag /= -1)
THEN
128 i = external_master_id
129 CALL external_comm%probe(source=i, tag=tag)
130 IF (tag == exit_tag) should_stop = .true.
133 IF (logger%para_env%is_source())
THEN
139 IF (t1 > t_last_file_check + 20.0_dp .OR. t1 <= t_last_file_check .OR. check_always)
THEN
141 t_last_file_check = t1
145 INQUIRE (file=
"WAIT", exist=should_wait)
146 IF (should_wait)
THEN
147 CALL open_file(file_name=
"WAITING", file_status=
"UNKNOWN", &
148 file_form=
"FORMATTED", file_action=
"WRITE", &
149 unit_number=unit_number)
151 "*** waiting till the file WAIT has been removed ***"
157 IF (t2 - t1 > 1.0_dp)
EXIT
160 INQUIRE (file=
"WAIT", exist=should_wait)
161 IF (.NOT. should_wait)
EXIT
163 CALL close_file(unit_number=unit_number, file_status=
"DELETE")
167 IF (.NOT. should_stop)
THEN
168 INQUIRE (file=exit_fname_level, exist=should_stop)
169 IF (should_stop)
THEN
170 CALL open_file(file_name=exit_fname_level, unit_number=unit_number)
171 CALL close_file(unit_number=unit_number, file_status=
"DELETE")
173 "*** "//flag//
" run terminated by external request ***"
177 IF (.NOT. should_stop)
THEN
178 INQUIRE (file=exit_fname, exist=should_stop)
179 IF (should_stop)
THEN
181 "*** "//trim(flag)//
" run terminated by external request ***"
185 IF (.NOT. should_stop)
THEN
186 INQUIRE (file=exit_gname_level, exist=should_stop)
187 IF (should_stop)
THEN
188 CALL open_file(file_name=exit_gname_level, unit_number=unit_number)
189 CALL close_file(unit_number=unit_number, file_status=
"DELETE")
191 "*** "//flag//
" run terminated by external request ***"
195 IF (.NOT. should_stop)
THEN
196 INQUIRE (file=exit_gname, exist=should_stop)
197 IF (should_stop)
THEN
199 "*** "//trim(flag)//
" run terminated by external request ***"
204 IF (
PRESENT(target_time))
THEN
205 my_target_time = target_time
206 my_start_time = start_time
207 ELSE IF (
PRESENT(globenv))
THEN
208 my_target_time = globenv%cp2k_target_time
209 my_start_time = globenv%cp2k_start_time
212 cpabort(
"Neither target_time nor globenv exists for external_control")
215 IF ((.NOT. should_stop) .AND. (my_target_time > 0.0_dp))
THEN
218 IF (time_check > my_target_time)
THEN
221 "*** "//trim(flag)//
" run terminated - exceeded requested execution time:", &
222 my_target_time,
" seconds", &
223 "*** Execution time now: ", time_check,
" seconds"
227 CALL logger%para_env%bcast(should_stop)
229 check_always = should_stop
231 CALL timestop(handle)
subroutine, public external_control(should_stop, flag, globenv, target_time, start_time, force_check)
External manipulations during a run : when the <PROJECT_NAME>.EXIT_$runtype command is sent the progr...
subroutine, public set_external_comm(comm, in_external_master_id, in_scf_energy_message_tag, in_exit_tag)
set the communicator to an external source or destination, to send messages (e.g. intermediate energi...
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.