26 #include "./base/base_uses.f90"
37 CHARACTER(len=*),
PARAMETER,
PRIVATE :: modulen =
'farming_methods'
50 TYPE(farming_env_type),
POINTER :: farming_env
51 INTEGER,
INTENT(IN) :: start, end
52 INTEGER,
INTENT(INOUT) :: current
53 INTEGER,
INTENT(OUT) :: todo
55 INTEGER :: icheck, idep, itry, ndep
58 IF (farming_env%cycle)
THEN
59 IF (current < start)
THEN
64 IF (current >
END) then
67 todo =
modulo(current - 1, farming_env%njobs) + 1
74 IF (farming_env%job(itry)%status == job_pending)
THEN
77 ndep =
SIZE(farming_env%job(itry)%dependencies)
79 dep:
DO idep = 1, ndep
80 DO icheck = start,
END
81 IF (farming_env%job(icheck)%status .NE. job_finished)
THEN
82 IF (farming_env%job(icheck)%id == farming_env%job(itry)%dependencies(idep))
THEN
105 IF (farming_env%job(itry)%status .EQ. job_running) dep_ok = .true.
119 TYPE(farming_env_type),
POINTER :: farming_env
120 TYPE(section_vals_type),
POINTER :: root_section
121 TYPE(mp_para_env_type),
POINTER :: para_env
123 CHARACTER(LEN=3) :: text
124 INTEGER :: i, iunit, n_rep_val, num_minions, &
126 INTEGER,
DIMENSION(:),
POINTER :: dependencies, i_vals
127 LOGICAL :: explicit, has_dep
128 TYPE(cp_logger_type),
POINTER :: logger
129 TYPE(section_vals_type),
POINTER :: farming_section, jobs_section, print_key
131 NULLIFY (farming_section, jobs_section, print_key, logger, dependencies, i_vals)
132 logger => cp_get_default_logger()
133 farming_env%group_size_wish_set = .false.
134 farming_env%ngroup_wish_set = .false.
135 farming_section => section_vals_get_subs_vals(root_section,
"FARMING")
137 IF (
ASSOCIATED(farming_env%group_partition))
THEN
138 DEALLOCATE (farming_env%group_partition)
145 CALL section_vals_val_get(farming_section,
"GROUP_PARTITION", &
147 IF (n_rep_val > 0)
THEN
148 CALL section_vals_val_get(farming_section,
"GROUP_PARTITION", &
150 ALLOCATE (farming_env%group_partition(0:
SIZE(i_vals) - 1))
151 farming_env%group_partition(:) = i_vals
152 farming_env%ngroup_wish_set = .true.
153 farming_env%ngroup_wish =
SIZE(i_vals)
155 CALL section_vals_val_get(farming_section,
"NGROUP", &
157 IF (n_rep_val > 0)
THEN
158 CALL section_vals_val_get(farming_section,
"NGROUP", &
159 i_val=farming_env%ngroup_wish)
160 farming_env%ngroup_wish_set = .true.
162 CALL section_vals_val_get(farming_section,
"GROUP_SIZE", &
163 i_val=farming_env%group_size_wish)
164 farming_env%group_size_wish_set = .true.
167 CALL section_vals_val_get(farming_section,
"STRIDE", &
168 i_val=farming_env%stride)
170 CALL section_vals_val_get(farming_section,
"RESTART_FILE_NAME", &
173 CALL section_vals_val_get(farming_section,
"RESTART_FILE_NAME", &
174 c_val=farming_env%restart_file_name)
176 print_key => section_vals_get_subs_vals(farming_section,
"RESTART")
177 farming_env%restart_file_name = cp_print_key_generate_filename(logger, print_key, extension=
".restart", &
181 CALL section_vals_val_get(farming_section,
"DO_RESTART", &
182 l_val=farming_env%restart)
183 CALL section_vals_val_get(farming_section,
"MAX_JOBS_PER_GROUP", &
184 i_val=farming_env%max_steps)
185 CALL section_vals_val_get(farming_section,
"CYCLE", &
186 l_val=farming_env%cycle)
187 CALL section_vals_val_get(farming_section,
"WAIT_TIME", &
188 r_val=farming_env%wait_time)
190 CALL section_vals_val_get(farming_section,
"CAPTAIN_MINION", &
191 l_val=farming_env%captain_minion)
193 jobs_section => section_vals_get_subs_vals(farming_section,
"JOB")
194 CALL section_vals_get(jobs_section, n_repetition=farming_env%njobs)
196 ALLOCATE (farming_env%Job(farming_env%njobs))
197 CALL init_job_type(farming_env%job)
200 DO i = 1, farming_env%njobs
201 CALL section_vals_val_get(jobs_section, i_rep_section=i, &
202 keyword_name=
"DIRECTORY", c_val=farming_env%Job(i)%cwd)
203 CALL section_vals_val_get(jobs_section, i_rep_section=i, &
204 keyword_name=
"INPUT_FILE_NAME", c_val=farming_env%Job(i)%input)
205 CALL section_vals_val_get(jobs_section, i_rep_section=i, &
206 keyword_name=
"OUTPUT_FILE_NAME", c_val=farming_env%Job(i)%output)
209 CALL section_vals_val_get(jobs_section, i_rep_section=i, &
210 keyword_name=
"JOB_ID", n_rep_val=n_rep_val)
211 IF (n_rep_val == 0)
THEN
212 farming_env%Job(i)%id = i
214 CALL section_vals_val_get(jobs_section, i_rep_section=i, &
215 keyword_name=
"JOB_ID", i_val=farming_env%Job(i)%id)
219 CALL section_vals_val_get(jobs_section, i_rep_section=i, &
220 keyword_name=
"DEPENDENCIES", n_rep_val=n_rep_val)
221 IF (n_rep_val == 0)
THEN
222 ALLOCATE (farming_env%Job(i)%dependencies(0))
224 CALL section_vals_val_get(jobs_section, i_rep_section=i, &
225 keyword_name=
"DEPENDENCIES", i_vals=dependencies)
226 ALLOCATE (farming_env%Job(i)%dependencies(
SIZE(dependencies, 1)))
227 farming_env%Job(i)%dependencies = dependencies
228 IF (
SIZE(dependencies, 1) .NE. 0) has_dep = .true.
233 cpassert(farming_env%captain_minion)
234 cpassert(.NOT. farming_env%cycle)
237 output_unit = cp_print_key_unit_nr(logger, farming_section,
"PROGRAM_RUN_INFO", &
241 IF (para_env%num_pe == 1)
THEN
242 farming_env%captain_minion = .false.
243 WRITE (output_unit, fmt=
"(T2,A)")
"FARMING| Captain-Minion setup not supported for serial runs"
245 IF (farming_env%captain_minion)
THEN
246 num_minions = para_env%num_pe - 1
248 num_minions = para_env%num_pe
251 IF (output_unit > 0)
THEN
252 WRITE (output_unit, fmt=
"(T2,A,T71,I10)")
"FARMING| Number of jobs found", farming_env%njobs
253 IF (farming_env%ngroup_wish_set)
THEN
254 WRITE (output_unit, fmt=
"(T2,A,T71,I10)")
"FARMING| Ngroup wish:", farming_env%ngroup_wish
255 IF (
ASSOCIATED(farming_env%group_partition))
THEN
256 WRITE (output_unit, fmt=
"(T2,A)", advance=
"NO")
"FARMING| User partition:"
257 DO i = 0,
SIZE(farming_env%group_partition) - 1
258 IF (
modulo(i, 4) == 0)
WRITE (output_unit, *)
259 WRITE (output_unit, fmt=
'(I4)', advance=
"NO") farming_env%group_partition(i)
261 WRITE (output_unit, *)
262 IF (sum(farming_env%group_partition) .NE. num_minions)
THEN
263 WRITE (output_unit, fmt=
"(T2,A,T61,I10,T71,I10)") &
264 "FARMING| WARNING : group partition CPUs not equal to the available number (ignoring Captain) ", &
265 num_minions, sum(farming_env%group_partition)
266 WRITE (output_unit, fmt=
"(T2,A)")
"FARMING| partition data ignored"
267 DEALLOCATE (farming_env%group_partition)
271 IF (farming_env%group_size_wish_set)
THEN
272 WRITE (output_unit, fmt=
"(T2,A,T71,I10)")
"FARMING| Group size wish:", &
273 farming_env%group_size_wish
275 WRITE (output_unit, fmt=
"(T2,A,T71,I10)")
"FARMING| Max steps :", farming_env%max_steps
276 IF (farming_env%cycle)
THEN
281 WRITE (output_unit, fmt=
"(T2,A,T78,A3)")
"FARMING| Cyclic jobs execution:", text
282 IF (farming_env%restart)
THEN
287 WRITE (output_unit, fmt=
"(T2,A,T78,A3)")
"FARMING| Restarting farm:", text
288 farming_env%restart_n = 1
289 IF (farming_env%restart)
THEN
290 iunit = get_unit_number()
291 OPEN (unit=iunit, file=farming_env%restart_file_name, iostat=stat)
293 READ (unit=iunit, fmt=*, iostat=stat) farming_env%restart_n
295 WRITE (output_unit,
"(T2,A)") &
296 "FARMING| ---- WARNING ---- failed to read from ("//trim(farming_env%restart_file_name)//
") starting at 1"
298 WRITE (output_unit,
"(T2,A)") &
299 "FARMING| restarting from ("//trim(farming_env%restart_file_name)//
")"
300 WRITE (output_unit,
"(T2,A,T71,I10)") &
301 "FARMING| restarting at ", farming_env%restart_n
304 WRITE (output_unit,
"(T2,A)") &
305 "FARMING| ---- WARNING ---- failed to open ("//trim(farming_env%restart_file_name)//
"), starting at 1"
307 CLOSE (iunit, iostat=stat)
310 CALL cp_print_key_finished_output(output_unit, logger, farming_section, &
313 CALL para_env%bcast(farming_env%restart_n)
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Utility routines to open and close files. Tracking of preconnections.
integer function, public get_unit_number(file_name)
Returns the first logical unit that is not preconnected.
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)
...
character(len=default_path_length) function, public cp_print_key_generate_filename(logger, print_key, middle_name, extension, my_local)
Utility function that returns a unit number to write the print key. Might open a file with a unique f...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
subroutine, public farming_parse_input(farming_env, root_section, para_env)
...
subroutine, public get_next_job(farming_env, start, END, current, todo)
...
integer, parameter, public do_nothing
integer, parameter, public do_wait
integer, parameter, public do_deadlock
elemental subroutine, public init_job_type(job)
provide a default initialization
integer, parameter, public job_finished
integer, parameter, public job_running
integer, parameter, public job_pending
Interface to the message passing library MPI.