257 def create_subjobs(self, job):
258 """
259 This function creates subjobs for the parent job passed in. It creates as many subjobs as required
260 by the number of input files up to the maximum set by `MaxSubjobsSplitter.max_subjobs`. If there are
261 more input files than `max_subjobs` it instead groups files by the minimum number per subjob in order to
262 respect the subjob limit e.g. If you have 11 input files and a maximum number of subjobs of 4, then it
263 will create 4 subjobs, 3 of them with 3 input files, and one with 2 input files.
264 """
265 if not job.input_files:
266 B2WARNING(f"Subjob splitting by input files requested, but no input files exist for {job}. No subjobs created.")
267 return
268
269
270 remaining_input_files = deque(job.input_files)
271
272 available_subjobs = self.max_subjobs
273 subjob_i = 0
274 while remaining_input_files:
275
276 num_input_files = ceil(len(remaining_input_files) / available_subjobs)
277
278 subjob_input_files = []
279 for i in range(num_input_files):
280 subjob_input_files.append(remaining_input_files.popleft())
281
282 job.create_subjob(subjob_i, input_files=subjob_input_files)
283 subjob_i += 1
284 available_subjobs -= 1
285
286 self.assign_arguments(job)
287 B2INFO(f"{self} created {subjob_i} Subjobs for {job}")
288
289