R doParallel foreach with error handling for independent workers

I need to run many random forest models, so I want to use doParallel on my 8-core server to speed things up.

However, some models need much longer than others, or may even be wrong. I would like to run 8 models in parallel, and if the model throws an error and / or is skipped, workers should just continue. Each model result is saved on the hard drive, so I can access and combine them later.

TryCatch

or

.errorhandling="remove" 

didn't solve the problem. I get

 Error in unserialize(socklist[[n]]) : error reading from connection

Code example: I tried it with% do% and model 2-7 successfully. However, in% dopar% I get the error shown

 foreach(model=1:8, .errorhandling="remove") %dopar% {


      tryCatch({
          outl <- rf_perform(...)
          saveRDS(outl,file=getwd() %+% "/temp/result_" %+% model %+% ".rds")

     }, error = function(e) {print(e)}, finally = {})
  }
+4
source share
1

, : , , , R can not , / -

5 300 , 16 .

cl <- makeCluster(16)
registerDoParallel(cl)
clusterExport(cl, "data")

#data must not be too large

, . doParallel , .

+2

Source: https://habr.com/ru/post/1622043/


All Articles