I need to run task over a range of input parameters with very different run times. I use parallel::clusterMap() to do this in parallel with dynamic scheduling. Sometimes the computation time is just not feasible for single problems. Is there any way of killing the cluster after some predefined time limit and still retrieve the completed tasks?
If I simply set the timeout parameter the cluster is killed without retrieving the already finished tasks. Minimal example (NOT working!):
f <- function(t) {Sys.sleep(t); return(t)}
t <- c(1, 1, 2, 15, 2, 1, 3, 4, 1, 1, 1,3)
cl <- makeCluster(3, timeout = 5)
as.numeric(clusterMap(cl, f, t, .scheduling = "dynamic"))
stopCluster(cl)