make_cluster: Make Mirai Cluster

View source: R/parallel.R

make_clusterR Documentation

Make Mirai Cluster

Description

make_cluster creates a cluster of type 'miraiCluster', which may be used as a cluster object for any function in the parallel base package such as clusterApply or parLapply.

stop_cluster stops a cluster created by make_cluster.

Usage

make_cluster(n, url = NULL, remote = NULL, ...)

stop_cluster(cl)

Arguments

n

integer number of nodes (automatically launched on the local machine unless 'url' is supplied).

url

[default NULL] (specify for remote nodes) the character URL on the host for remote nodes to dial into, including a port accepting incoming connections, e.g. 'tcp://10.75.37.40:5555'. Specify a URL with the scheme 'tls+tcp://' to use secure TLS connections.

remote

[default NULL] (specify to launch remote nodes) a remote launch configuration generated by remote_config or ssh_config. If not supplied, nodes may be deployed manually on remote resources.

...

additional arguments passed onto daemons.

cl

a 'miraiCluster'.

Value

For make_cluster: An object of class 'miraiCluster' and 'cluster'. Each 'miraiCluster' has an automatically assigned ID and 'n' nodes of class 'miraiNode'. If 'url' is supplied but not 'remote', the shell commands for deployment of nodes on remote resources is printed in interactive sessions.

For stop_cluster: invisible NULL.

Remote Nodes

Specify 'url' and 'n' to set up a host connection for remote nodes to dial into. 'n' defaults to one if not specified.

Also specify 'remote' to launch the nodes using a configuration generated by remote_config or ssh_config. In this case, the number of nodes is inferred from the configuration provided and 'n' is disregarded.

If 'remote' is not supplied, the shell commands for deploying nodes manually on remote resources are automatically printed in interactive sessions.

launch_remote may be called at any time on a 'miraiCluster' to return the shell commands for deployment of all nodes, or on a 'miraiNode' to return the command for a single node.

Status

Call status on a 'miraiCluster' to check the number of currently active connections as well as the host URL.

Note

Requires R >= 4.4 (currently R-devel). Clusters created with this function will not work with prior R versions. The functionality is experimental prior to release of R 4.4 and the interface is consequently subject to change at any time.

The default behaviour of clusters created by this function is designed to map as closely as possible to clusters created by the parallel package. However, '...' arguments are passed onto daemons for additional customisation if desired, although resultant behaviour may not be supported.

Examples

if (interactive()) {
# Only run examples in interactive R sessions

cl <- make_cluster(2)
cl
cl[[1L]]

Sys.sleep(0.5)
status(cl)

stop_cluster(cl)

}


mirai documentation built on Nov. 16, 2023, 5:08 p.m.