120 TYPE(farming_env_type),
POINTER :: farming_env
121 TYPE(section_vals_type),
POINTER :: root_section
122 TYPE(mp_para_env_type),
POINTER :: para_env
124 CHARACTER(LEN=3) :: text
125 INTEGER :: i, iunit, n_rep_val, num_minions, &
127 INTEGER,
DIMENSION(:),
POINTER :: dependencies, i_vals
128 LOGICAL :: exists, explicit, has_dep
129 TYPE(cp_logger_type),
POINTER :: logger
130 TYPE(section_vals_type),
POINTER :: farming_section, jobs_section, print_key
132 NULLIFY (farming_section, jobs_section, print_key, logger, dependencies, i_vals)
133 logger => cp_get_default_logger()
134 farming_env%group_size_wish_set = .false.
135 farming_env%ngroup_wish_set = .false.
136 farming_section => section_vals_get_subs_vals(root_section,
"FARMING")
138 IF (
ASSOCIATED(farming_env%group_partition))
THEN
139 DEALLOCATE (farming_env%group_partition)
146 CALL section_vals_val_get(farming_section,
"GROUP_PARTITION", &
148 IF (n_rep_val > 0)
THEN
149 CALL section_vals_val_get(farming_section,
"GROUP_PARTITION", &
151 ALLOCATE (farming_env%group_partition(0:
SIZE(i_vals) - 1))
152 farming_env%group_partition(:) = i_vals
153 farming_env%ngroup_wish_set = .true.
154 farming_env%ngroup_wish =
SIZE(i_vals)
156 CALL section_vals_val_get(farming_section,
"NGROUP", &
158 IF (n_rep_val > 0)
THEN
159 CALL section_vals_val_get(farming_section,
"NGROUP", &
160 i_val=farming_env%ngroup_wish)
161 farming_env%ngroup_wish_set = .true.
163 CALL section_vals_val_get(farming_section,
"GROUP_SIZE", &
164 i_val=farming_env%group_size_wish)
165 farming_env%group_size_wish_set = .true.
168 CALL section_vals_val_get(farming_section,
"STRIDE", &
169 i_val=farming_env%stride)
171 CALL section_vals_val_get(farming_section,
"RESTART_FILE_NAME", &
174 CALL section_vals_val_get(farming_section,
"RESTART_FILE_NAME", &
175 c_val=farming_env%restart_file_name)
177 print_key => section_vals_get_subs_vals(farming_section,
"RESTART")
178 farming_env%restart_file_name = cp_print_key_generate_filename(logger, print_key, extension=
".restart", &
182 CALL section_vals_val_get(farming_section,
"DO_RESTART", &
183 l_val=farming_env%restart)
184 CALL section_vals_val_get(farming_section,
"MAX_JOBS_PER_GROUP", &
185 i_val=farming_env%max_steps)
186 CALL section_vals_val_get(farming_section,
"CYCLE", &
187 l_val=farming_env%cycle)
188 CALL section_vals_val_get(farming_section,
"WAIT_TIME", &
189 r_val=farming_env%wait_time)
191 CALL section_vals_val_get(farming_section,
"CAPTAIN_MINION", &
192 l_val=farming_env%captain_minion)
194 jobs_section => section_vals_get_subs_vals(farming_section,
"JOB")
195 CALL section_vals_get(jobs_section, n_repetition=farming_env%njobs)
197 ALLOCATE (farming_env%Job(farming_env%njobs))
198 CALL init_job_type(farming_env%job)
201 DO i = 1, farming_env%njobs
202 CALL section_vals_val_get(jobs_section, i_rep_section=i, &
203 keyword_name=
"DIRECTORY", c_val=farming_env%Job(i)%cwd)
204 CALL section_vals_val_get(jobs_section, i_rep_section=i, &
205 keyword_name=
"INPUT_FILE_NAME", c_val=farming_env%Job(i)%input)
206 CALL section_vals_val_get(jobs_section, i_rep_section=i, &
207 keyword_name=
"OUTPUT_FILE_NAME", c_val=farming_env%Job(i)%output)
210 CALL section_vals_val_get(jobs_section, i_rep_section=i, &
211 keyword_name=
"JOB_ID", n_rep_val=n_rep_val)
212 IF (n_rep_val == 0)
THEN
213 farming_env%Job(i)%id = i
215 CALL section_vals_val_get(jobs_section, i_rep_section=i, &
216 keyword_name=
"JOB_ID", i_val=farming_env%Job(i)%id)
220 CALL section_vals_val_get(jobs_section, i_rep_section=i, &
221 keyword_name=
"DEPENDENCIES", n_rep_val=n_rep_val)
222 IF (n_rep_val == 0)
THEN
223 ALLOCATE (farming_env%Job(i)%dependencies(0))
225 CALL section_vals_val_get(jobs_section, i_rep_section=i, &
226 keyword_name=
"DEPENDENCIES", i_vals=dependencies)
227 ALLOCATE (farming_env%Job(i)%dependencies(
SIZE(dependencies, 1)))
228 farming_env%Job(i)%dependencies = dependencies
229 IF (
SIZE(dependencies, 1) /= 0) has_dep = .true.
234 cpassert(farming_env%captain_minion)
235 cpassert(.NOT. farming_env%cycle)
238 output_unit = cp_print_key_unit_nr(logger, farming_section,
"PROGRAM_RUN_INFO", &
242 IF (para_env%num_pe == 1)
THEN
243 farming_env%captain_minion = .false.
244 WRITE (output_unit, fmt=
"(T2,A)")
"FARMING| Captain-Minion setup not supported for serial runs"
246 IF (farming_env%captain_minion)
THEN
247 num_minions = para_env%num_pe - 1
249 num_minions = para_env%num_pe
252 IF (output_unit > 0)
THEN
253 WRITE (output_unit, fmt=
"(T2,A,T71,I10)")
"FARMING| Number of jobs found", farming_env%njobs
254 IF (farming_env%ngroup_wish_set)
THEN
255 WRITE (output_unit, fmt=
"(T2,A,T71,I10)")
"FARMING| Ngroup wish:", farming_env%ngroup_wish
256 IF (
ASSOCIATED(farming_env%group_partition))
THEN
257 WRITE (output_unit, fmt=
"(T2,A)", advance=
"NO")
"FARMING| User partition:"
258 DO i = 0,
SIZE(farming_env%group_partition) - 1
259 IF (
modulo(i, 4) == 0)
WRITE (output_unit, *)
260 WRITE (output_unit, fmt=
'(I4)', advance=
"NO") farming_env%group_partition(i)
262 WRITE (output_unit, *)
263 IF (sum(farming_env%group_partition) /= num_minions)
THEN
264 WRITE (output_unit, fmt=
"(T2,A,T61,I10,T71,I10)") &
265 "FARMING| WARNING : group partition CPUs not equal to the available number (ignoring Captain) ", &
266 num_minions, sum(farming_env%group_partition)
267 WRITE (output_unit, fmt=
"(T2,A)")
"FARMING| partition data ignored"
268 DEALLOCATE (farming_env%group_partition)
272 IF (farming_env%group_size_wish_set)
THEN
273 WRITE (output_unit, fmt=
"(T2,A,T71,I10)")
"FARMING| Group size wish:", &
274 farming_env%group_size_wish
276 WRITE (output_unit, fmt=
"(T2,A,T71,I10)")
"FARMING| Max steps :", farming_env%max_steps
277 IF (farming_env%cycle)
THEN
282 WRITE (output_unit, fmt=
"(T2,A,T78,A3)")
"FARMING| Cyclic jobs execution:", text
283 IF (farming_env%restart)
THEN
288 WRITE (output_unit, fmt=
"(T2,A,T78,A3)")
"FARMING| Restarting farm:", text
289 farming_env%restart_n = 1
290 IF (farming_env%restart)
THEN
292 INQUIRE (file=farming_env%restart_file_name, exist=exists)
294 CALL open_file(unit_number=iunit, &
295 file_name=farming_env%restart_file_name)
296 READ (unit=iunit, fmt=*, iostat=stat) farming_env%restart_n
298 farming_env%restart_n = 1
299 WRITE (unit=output_unit, fmt=
"(T2,A)") &
300 "FARMING| ---- WARNING ---- failed to read from ("// &
301 trim(farming_env%restart_file_name)//
") starting at 1"
303 WRITE (unit=output_unit, fmt=
"(T2,A)") &
304 "FARMING| restarting from ("//trim(farming_env%restart_file_name)//
")"
305 WRITE (unit=output_unit, fmt=
"(T2,A,T71,I10)") &
306 "FARMING| restarting at ", farming_env%restart_n
308 CALL close_file(unit_number=iunit)
310 WRITE (unit=output_unit, fmt=
"(T2,A)") &
311 "FARMING| ---- WARNING ---- restart file ("// &
312 trim(farming_env%restart_file_name)//
") not found, starting at 1"
316 CALL cp_print_key_finished_output(output_unit, logger, farming_section, &
319 CALL para_env%bcast(farming_env%restart_n)