41 #include "../base/base_uses.f90"
46 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'swarm'
61 SUBROUTINE run_swarm(input_declaration, root_section, para_env, globenv, input_path)
62 TYPE(section_type),
POINTER :: input_declaration
63 TYPE(section_vals_type),
POINTER :: root_section
64 TYPE(mp_para_env_type),
POINTER :: para_env
65 TYPE(global_environment_type),
POINTER :: globenv
66 CHARACTER(LEN=*),
INTENT(IN) :: input_path
68 CHARACTER(len=*),
PARAMETER :: routinen =
'run_swarm'
70 INTEGER :: handle, iw, n_workers
71 TYPE(cp_logger_type),
POINTER :: logger
73 CALL timeset(routinen, handle)
77 "SWARM%PRINT%MASTER_RUN_INFO", extension=
".masterLog")
79 IF (iw > 0)
WRITE (iw,
"(A)")
" SWARM| Ready to roll :-)"
84 IF (n_workers == 1 .AND. para_env%num_pe == 1)
THEN
85 IF (iw > 0)
WRITE (iw,
"(A)")
" SWARM| Running in single worker mode."
86 CALL swarm_serial_driver(input_declaration, root_section, input_path, para_env, globenv)
88 IF (iw > 0)
WRITE (iw,
"(A)")
" SWARM| Running in master / workers mode."
90 CALL swarm_parallel_driver(n_workers, input_declaration, root_section, input_path, para_env, globenv, iw)
105 SUBROUTINE swarm_serial_driver(input_declaration, root_section, input_path, para_env, globenv)
106 TYPE(section_type),
POINTER :: input_declaration
107 TYPE(section_vals_type),
POINTER :: root_section
108 CHARACTER(LEN=*),
INTENT(IN) :: input_path
109 TYPE(mp_para_env_type),
POINTER :: para_env
110 TYPE(global_environment_type),
POINTER :: globenv
113 LOGICAL :: should_stop
114 TYPE(swarm_master_type) :: master
115 TYPE(swarm_message_type) :: cmd, report
116 TYPE(swarm_worker_type) :: worker
120 input_path, worker_id=1)
122 CALL swarm_message_add(report,
"worker_id", 1)
123 CALL swarm_message_add(report,
"status",
"initial_hello")
125 should_stop = .false.
126 DO WHILE (.NOT. should_stop)
127 CALL timeset(
"swarm_worker_await_reply", handle)
129 CALL timestop(handle)
139 END SUBROUTINE swarm_serial_driver
152 SUBROUTINE swarm_parallel_driver(n_workers, input_declaration, root_section, input_path, para_env, globenv, iw)
153 INTEGER,
INTENT(IN) :: n_workers
154 TYPE(section_type),
POINTER :: input_declaration
155 TYPE(section_vals_type),
POINTER :: root_section
156 CHARACTER(LEN=*),
INTENT(IN) :: input_path
157 TYPE(mp_para_env_type),
POINTER :: para_env
158 TYPE(global_environment_type),
POINTER :: globenv
159 INTEGER,
INTENT(IN) :: iw
167 CALL swarm_parallel_worker_driver(
swarm_mpi, input_declaration, worker_id, root_section, input_path)
169 CALL swarm_parallel_master_driver(
swarm_mpi, n_workers, root_section, globenv)
174 END SUBROUTINE swarm_parallel_driver
185 SUBROUTINE swarm_parallel_worker_driver(swarm_mpi, input_declaration, worker_id, root_section, input_path)
186 TYPE(swarm_mpi_type),
INTENT(IN) ::
swarm_mpi
187 TYPE(section_type),
POINTER :: input_declaration
188 INTEGER,
INTENT(IN) :: worker_id
189 TYPE(section_vals_type),
POINTER :: root_section
190 CHARACTER(LEN=*),
INTENT(IN) :: input_path
193 LOGICAL :: should_stop
194 TYPE(swarm_message_type) :: cmd, report
195 TYPE(swarm_worker_type) :: worker
198 root_section, input_path, worker_id=worker_id)
200 CALL swarm_message_add(report,
"worker_id", worker_id)
201 CALL swarm_message_add(report,
"status",
"initial_hello")
203 should_stop = .false.
204 DO WHILE (.NOT. should_stop)
205 CALL timeset(
"swarm_worker_await_reply", handle)
209 CALL timestop(handle)
217 END SUBROUTINE swarm_parallel_worker_driver
227 SUBROUTINE swarm_parallel_master_driver(swarm_mpi, n_workers, root_section, globenv)
228 TYPE(swarm_mpi_type),
INTENT(IN) ::
swarm_mpi
229 INTEGER,
INTENT(IN) :: n_workers
230 TYPE(section_vals_type),
POINTER :: root_section
231 TYPE(global_environment_type),
POINTER :: globenv
233 CHARACTER(len=default_string_length) :: command
234 INTEGER :: i_shutdowns, j, wid
235 LOGICAL,
DIMENSION(n_workers) :: is_waiting
236 TYPE(swarm_master_type) :: master
237 TYPE(swarm_message_type) :: cmd, report
239 is_waiting(:) = .false.
246 DO WHILE (i_shutdowns < n_workers)
250 j = mod(j + 1, n_workers + 1)
253 ELSE IF (is_waiting(j))
THEN
254 is_waiting(j) = .false.
255 CALL swarm_message_add(report,
"worker_id", j)
256 CALL swarm_message_add(report,
"status",
"wait_done")
264 CALL swarm_message_get(cmd,
"command", command)
265 IF (trim(command) ==
"wait")
THEN
266 CALL swarm_message_get(cmd,
"worker_id", wid)
267 is_waiting(wid) = .true.
270 IF (trim(command) ==
"shutdown") i_shutdowns = i_shutdowns + 1
277 END SUBROUTINE swarm_parallel_master_driver
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
Define type storing the global information of a run. Keep the amount of stored data small....
Defines the basic variable types.
integer, parameter, public default_string_length
Interface to the message passing library MPI.
Master's routines for the swarm-framework.
subroutine, public swarm_master_finalize(master)
Finalizes the swarm master.
subroutine, public swarm_master_steer(master, report, cmd)
Central steering routine of the swarm master.
subroutine, public swarm_master_init(master, para_env, globenv, root_section, n_workers)
Initializes the swarm master.
Swarm-message, a convenient data-container for with build-in serialization.
subroutine, public swarm_message_free(msg)
Deallocates all entries contained in a swarm-message.
Handles the MPI communication of the swarm framework.
subroutine, public swarm_mpi_init(swarm_mpi, world_para_env, root_section, n_workers, worker_id, iw)
Initialize MPI communicators for a swarm run.
subroutine, public swarm_mpi_send_command(swarm_mpi, cmd)
Sends a command via MPI.
subroutine, public swarm_mpi_recv_report(swarm_mpi, report)
Receives a report via MPI.
subroutine, public swarm_mpi_recv_command(swarm_mpi, cmd)
Receives a command via MPI and broadcasts it within a worker.
subroutine, public swarm_mpi_send_report(swarm_mpi, report)
Sends a report via MPI.
subroutine, public swarm_mpi_finalize(swarm_mpi, root_section)
Finalizes the MPI communicators of a swarm run.
Workers's routines for the swarm-framework.
subroutine, public swarm_worker_finalize(worker)
Finalizes a swarm worker.
subroutine, public swarm_worker_execute(worker, cmd, report, should_stop)
Central execute routine of the swarm worker.
subroutine, public swarm_worker_init(worker, para_env, input_declaration, root_section, input_path, worker_id)
Initializes a swarm worker.
Swarm-framwork, provides a convenient master/worker architecture.
subroutine, public run_swarm(input_declaration, root_section, para_env, globenv, input_path)
Central driver routine of the swarm framework, called by cp2k_runs.F.