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