Coerce an Object to a Cluster Object

as.cluster(x, ...)

# S3 method for cluster
as.cluster(x, ...)

# S3 method for list
as.cluster(x, ...)

# S3 method for SOCKnode
as.cluster(x, ...)

# S3 method for SOCK0node
as.cluster(x, ...)

# S3 method for cluster
c(..., recursive = FALSE)

Arguments

x

An object to be coerced.

...

Additional arguments passed to the underlying coercion method. For c(...), the clusters and cluster nodes to be combined.

recursive

Not used.

Value

An object of class cluster.

c(...) combine multiple clusters and / or cluster nodes into one cluster returned as an of class cluster. A warning will be produced if there are duplicated nodes in the resulting cluster.

Examples

options(parallelly.debug = TRUE) cl1 <- makeClusterPSOCK(2, dryrun = TRUE)
#> [local output] Workers: [n = 2] ‘localhost’, ‘localhost’
#> [local output] Base port: 11045
#> [local output] Getting setup options for 2 cluster nodes ...
#> [local output] - Node 1 of 2 ...
#> [local output] Rscript port: 11045
#> [local output] - Node 2 of 2 ...
#> [local output] Rscript port: 11045
#> [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=11045 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=11045 OUT=/dev/null TIMEOUT=2592000 XDR=FALSE SETUPTIMEOUT=120 SETUPSTRATEGY=sequential #>
#> [local output] Creating node 2 of 2 ... done
#> [local output] - collecting session information
cl2 <- makeClusterPSOCK(c("n1", "server.remote.org"), dryrun = TRUE)
#> [local output] Workers: [n = 2] ‘n1’, ‘server.remote.org’
#> [local output] Base port: 11517
#> [local output] Getting setup options for 2 cluster nodes ...
#> [local output] - Node 1 of 2 ...
#> [local output] Rscript port: 11517 + 0 = 11517
#> [local output] Will search for all 'rshcmd' available
#> [local output] Found the following available 'rshcmd': #> [local output] 1. ‘/usr/bin/ssh’ [type=‘ssh’, version=‘OpenSSH_7.6p1 Ubuntu-4ubuntu0.5, OpenSSL 1.0.2n 7 Dec 2017’]
#> [local output] Using 'rshcmd': ‘/usr/bin/ssh’ [type=‘ssh’, version=‘OpenSSH_7.6p1 Ubuntu-4ubuntu0.5, OpenSSL 1.0.2n 7 Dec 2017’]
#> [local output] - Node 2 of 2 ...
#> [local output] Rscript port: 11517 + 1 = 11518
#> [local output] Will search for all 'rshcmd' available
#> [local output] Found the following available 'rshcmd': #> [local output] 1. ‘/usr/bin/ssh’ [type=‘ssh’, version=‘OpenSSH_7.6p1 Ubuntu-4ubuntu0.5, OpenSSL 1.0.2n 7 Dec 2017’]
#> [local output] Using 'rshcmd': ‘/usr/bin/ssh’ [type=‘ssh’, version=‘OpenSSH_7.6p1 Ubuntu-4ubuntu0.5, OpenSSL 1.0.2n 7 Dec 2017’]
#> [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, (i) login into external machine ‘n1’: #> #> '/usr/bin/ssh' -R 11517:localhost:11517 n1 #> #> and (ii) start worker #1 from there: #> #> '/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=11517 OUT=/dev/null TIMEOUT=2592000 XDR=FALSE SETUPTIMEOUT=120 SETUPSTRATEGY=sequential #> #> Alternatively, start worker #1 from the local machine by combining both step in a single call: #> #> '/usr/bin/ssh' -R 11517:localhost:11517 n1 "'/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=11517 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, (i) login into external machine ‘server.remote.org’: #> #> '/usr/bin/ssh' -R 11518:localhost:11517 server.remote.org #> #> and (ii) start worker #2 from there: #> #> 'Rscript' --default-packages=datasets,utils,grDevices,graphics,stats,methods -e 'workRSOCK <- tryCatch(parallel:::.workRSOCK, error=function(e) parallel:::.slaveRSOCK); workRSOCK()' MASTER=localhost PORT=11518 OUT=/dev/null TIMEOUT=2592000 XDR=FALSE SETUPTIMEOUT=120 SETUPSTRATEGY=sequential #> #> Alternatively, start worker #2 from the local machine by combining both step in a single call: #> #> '/usr/bin/ssh' -R 11518:localhost:11517 server.remote.org "'Rscript' --default-packages=datasets,utils,grDevices,graphics,stats,methods -e 'workRSOCK <- tryCatch(parallel:::.workRSOCK, error=function(e) parallel:::.slaveRSOCK); workRSOCK()' MASTER=localhost PORT=11518 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 <- c(cl1, cl2)
#> Warning: The combined cluster contains 1 duplicated nodes
print(cl)
#> Socket cluster with 2 nodes where 2 nodes are on host ‘NA’ (R version and platform not queried)