mllg / batchtools

Tools for computation on batch systems
https://mllg.github.io/batchtools/
GNU Lesser General Public License v3.0
169 stars 51 forks source link

Execution order of jobs in the same chunk #272

Open bommert opened 3 years ago

bommert commented 3 years ago

Question: Can I control the execution order of jobs in the same chunk?

The situation is that I have a registry with many jobs and I want to use chunking. Some of the jobs are really fast, others are quite slow. I have more or less accurate run time estimates. I would like the jobs within one chunk to be executed such that the slowest job is executed first and the fastest is executed last. The idea is that if the batch job runs into the walltime, it would be nice to stop while executing a rather fast job (and thus waste less computational resources). Is there any way to control the execution order within one chunk?

On my local computer I have tried (with cluster function interactive) the following code:

makeRegistry("testReg")
f = function(i) {
  Sys.sleep(10)
  return(Sys.time())
}
batchMap(i = 1:4, fun = f)

jobs = data.frame(job.id = 4:1, chunk = c(1, 2, 1, 2))
submitJobs(jobs)

jobs
  job.id chunk
1      4     1
2      3     2
3      2     1
4      1     2

reduceResultsDataTable(findDone())
   job.id              result
1:      1 2021-04-09 12:55:19
2:      2 2021-04-09 12:54:59
3:      3 2021-04-09 12:55:29
4:      4 2021-04-09 12:55:09

So it seems that chunk 1 is executed before chunk 2 but within one chunk, the jobs are executed sorted by job.id, even though I passed them to submitJobs in a different order.