Registers a finalizer to a cluster such that the cluster will be stopped when garbage collected

autoStopCluster(cl, debug = FALSE)

Arguments

cl

A cluster object created by for instance makeClusterPSOCK() or parallel::makeCluster().

debug

If TRUE, then debug messages are produced when the cluster is garbage collected.

Value

The cluster object with attribute gcMe set.

See also

The cluster is stopped using stopCluster(cl).

Examples

options(parallelly.debug = TRUE) cl <- makeClusterPSOCK(2, dryrun = TRUE)
#> [local output] Workers: [n = 2] ‘localhost’, ‘localhost’
#> [local output] Base port: 11886
#> [local output] Getting setup options for 2 cluster nodes ...
#> [local output] - Node 1 of 2 ...
#> [local output] Rscript port: 11886
#> [local output] - Node 2 of 2 ...
#> [local output] Rscript port: 11886
#> [local output] Getting setup options for 2 cluster nodes ... done
#> [local output] Creating node 1 of 2 ...
#> [local output] - setting up node
#> [local output] - attempt #1 of 3
#> ---------------------------------------------------------------------- #> Manually, start worker #1 on local machine ‘localhost’ with: #> #> '/home/hb/software/R-devel/R-4-1-branch/lib/R/bin/Rscript' --default-packages=datasets,utils,grDevices,graphics,stats,methods -e 'workRSOCK <- tryCatch(parallel:::.workRSOCK, error=function(e) parallel:::.slaveRSOCK); workRSOCK()' MASTER=localhost PORT=11886 OUT=/dev/null TIMEOUT=2592000 XDR=FALSE SETUPTIMEOUT=120 SETUPSTRATEGY=sequential #>
#> [local output] Creating node 1 of 2 ... done
#> [local output] Creating node 2 of 2 ...
#> [local output] - setting up node
#> [local output] - attempt #1 of 3
#> ---------------------------------------------------------------------- #> Manually, start worker #2 on local machine ‘localhost’ with: #> #> '/home/hb/software/R-devel/R-4-1-branch/lib/R/bin/Rscript' --default-packages=datasets,utils,grDevices,graphics,stats,methods -e 'workRSOCK <- tryCatch(parallel:::.workRSOCK, error=function(e) parallel:::.slaveRSOCK); workRSOCK()' MASTER=localhost PORT=11886 OUT=/dev/null TIMEOUT=2592000 XDR=FALSE SETUPTIMEOUT=120 SETUPSTRATEGY=sequential #>
#> [local output] Creating node 2 of 2 ... done
#> [local output] - collecting session information
cl <- autoStopCluster(cl) print(cl)
#> Socket cluster with 1 nodes where 1 node is on host ‘NA’ (R version and platform not queried)
rm(list = "cl") gc()
#> used (Mb) gc trigger (Mb) max used (Mb) #> Ncells 695630 37.2 1314725 70.3 1314725 70.3 #> Vcells 1332123 10.2 8388608 64.0 1889835 14.5