27 #include "./base/base_uses.f90"
33 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'cp_external_control'
38 TYPE(mp_comm_type),
SAVE :: external_comm
39 INTEGER,
SAVE :: external_master_id = -1
40 INTEGER,
SAVE :: scf_energy_message_tag = -1
41 INTEGER,
SAVE :: exit_tag = -1
56 in_scf_energy_message_tag, in_exit_tag)
57 CLASS(mp_comm_type),
INTENT(IN) :: comm
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 .GE. 0)
64 external_master_id = in_external_master_id
66 IF (
PRESENT(in_scf_energy_message_tag)) &
67 scf_energy_message_tag = in_scf_energy_message_tag
68 IF (
PRESENT(in_exit_tag))
THEN
70 cpassert(in_exit_tag .NE. -1)
71 exit_tag = in_exit_tag
89 SUBROUTINE external_control(should_stop, flag, globenv, target_time, start_time, force_check)
91 LOGICAL,
INTENT(OUT) :: should_stop
92 CHARACTER(LEN=*),
INTENT(IN) :: flag
93 TYPE(global_environment_type),
OPTIONAL,
POINTER :: globenv
94 REAL(
dp),
OPTIONAL :: target_time, start_time
95 LOGICAL,
OPTIONAL :: force_check
97 CHARACTER(LEN=*),
PARAMETER :: routinen =
'external_control'
99 CHARACTER(LEN=default_string_length) :: exit_fname, exit_fname_level, &
100 exit_gname, exit_gname_level
101 INTEGER :: handle, i, tag, unit_number
102 LOGICAL :: should_wait
103 LOGICAL,
SAVE :: check_always = .false.
104 REAL(kind=
dp) :: my_start_time, my_target_time, t1, t2, &
106 REAL(kind=
dp),
SAVE :: t_last_file_check = 0.0_dp
107 TYPE(cp_logger_type),
POINTER :: logger
109 CALL timeset(routinen, handle)
112 should_stop = .false.
114 IF (
PRESENT(force_check))
THEN
115 IF (force_check)
THEN
116 check_always = .true.
121 exit_gname_level = trim(exit_gname)//
"_"//trim(flag)
122 exit_fname = trim(logger%iter_info%project_name)//
"."//trim(exit_gname)
123 exit_fname_level = trim(logger%iter_info%project_name)//
"."//trim(exit_gname_level)
126 IF (exit_tag .NE. -1)
THEN
127 i = external_master_id
128 CALL external_comm%probe(source=i, tag=tag)
129 IF (tag .EQ. exit_tag) should_stop = .true.
132 IF (logger%para_env%is_source())
THEN
138 IF (t1 > t_last_file_check + 20.0_dp .OR. t1 <= t_last_file_check .OR. check_always)
THEN
140 t_last_file_check = t1
144 INQUIRE (file=
"WAIT", exist=should_wait)
145 IF (should_wait)
THEN
146 CALL open_file(file_name=
"WAITING", file_status=
"UNKNOWN", &
147 file_form=
"FORMATTED", file_action=
"WRITE", &
148 unit_number=unit_number)
150 "*** waiting till the file WAIT has been removed ***"
156 IF (t2 - t1 > 1.0_dp)
EXIT
159 INQUIRE (file=
"WAIT", exist=should_wait)
160 IF (.NOT. should_wait)
EXIT
162 CALL close_file(unit_number=unit_number, file_status=
"DELETE")
166 IF (.NOT. should_stop)
THEN
167 INQUIRE (file=exit_fname_level, exist=should_stop)
168 IF (should_stop)
THEN
169 CALL open_file(file_name=exit_fname_level, unit_number=unit_number)
170 CALL close_file(unit_number=unit_number, file_status=
"DELETE")
172 "*** "//flag//
" run terminated by external request ***"
176 IF (.NOT. should_stop)
THEN
177 INQUIRE (file=exit_fname, exist=should_stop)
178 IF (should_stop)
THEN
180 "*** "//trim(flag)//
" run terminated by external request ***"
184 IF (.NOT. should_stop)
THEN
185 INQUIRE (file=exit_gname_level, exist=should_stop)
186 IF (should_stop)
THEN
187 CALL open_file(file_name=exit_gname_level, unit_number=unit_number)
188 CALL close_file(unit_number=unit_number, file_status=
"DELETE")
190 "*** "//flag//
" run terminated by external request ***"
194 IF (.NOT. should_stop)
THEN
195 INQUIRE (file=exit_gname, exist=should_stop)
196 IF (should_stop)
THEN
198 "*** "//trim(flag)//
" run terminated by external request ***"
203 IF (
PRESENT(target_time))
THEN
204 my_target_time = target_time
205 my_start_time = start_time
206 ELSEIF (
PRESENT(globenv))
THEN
207 my_target_time = globenv%cp2k_target_time
208 my_start_time = globenv%cp2k_start_time
214 IF ((.NOT. should_stop) .AND. (my_target_time > 0.0_dp))
THEN
217 IF (time_check .GT. my_target_time)
THEN
220 "*** "//trim(flag)//
" run terminated - exceeded requested execution time:", &
221 my_target_time,
" seconds.", &
222 "*** Execution time now: ", time_check,
" seconds."
226 CALL logger%para_env%bcast(should_stop)
228 check_always = should_stop
230 CALL timestop(handle)
Routines to handle the external control of CP2K.
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...
Utility routines to open and close files. Tracking of preconnections.
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.
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
Define type storing the global information of a run. Keep the amount of stored data small....
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
Machine interface based on Fortran 2003 and POSIX.
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Interface to the message passing library MPI.