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: 11289
#> [local output] Getting setup options for 2 cluster nodes ...
#> [local output] - Node 1 of 2 ...
#> [local output] Rscript port: 11289
#> [local output] - Node 2 of 2 ...
#> [local output] Rscript port: 11289
#> [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=11289 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=11289 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). This cluster is registered to be automatically stopped by the garbage collector
rm(list = "cl") gc()
#> used (Mb) gc trigger (Mb) max used (Mb) #> Ncells 699406 37.4 1322490 70.7 1322490 70.7 #> Vcells 1334457 10.2 8388608 64.0 1891187 14.5