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

cl <- makeClusterPSOCK(2, dryrun = TRUE)
#> ----------------------------------------------------------------------
#> Manually, start worker #1 on local machine ‘localhost’ with:
#> 
#>   '/home/hb/shared/software/CBI/R-4.2.0-gcc9/lib/R/bin/Rscript' --default-packages=datasets,utils,grDevices,graphics,stats,methods -e 'options(socketOptions = "no-delay")' -e 'workRSOCK <- tryCatch(parallel:::.workRSOCK, error=function(e) parallel:::.slaveRSOCK); workRSOCK()' MASTER=localhost PORT=11057 OUT=/dev/null TIMEOUT=2592000 XDR=FALSE SETUPTIMEOUT=120 SETUPSTRATEGY=sequential
#> 
#> ----------------------------------------------------------------------
#> Manually, start worker #2 on local machine ‘localhost’ with:
#> 
#>   '/home/hb/shared/software/CBI/R-4.2.0-gcc9/lib/R/bin/Rscript' --default-packages=datasets,utils,grDevices,graphics,stats,methods -e 'options(socketOptions = "no-delay")' -e 'workRSOCK <- tryCatch(parallel:::.workRSOCK, error=function(e) parallel:::.slaveRSOCK); workRSOCK()' MASTER=localhost PORT=11057 OUT=/dev/null TIMEOUT=2592000 XDR=FALSE SETUPTIMEOUT=120 SETUPSTRATEGY=sequential
#> 
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  808529 43.2    1404760 75.1  1404760 75.1
#> Vcells 1503833 11.5    8388608 64.0  2309985 17.7