| 87768 |
luke |
1 |
% File src/library/parallel/man/makeCluster.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 87768 |
luke |
3 |
% Copyright 2003-2025 R Core Team
|
| 56599 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 56646 |
ripley |
6 |
\name{makeCluster}
|
|
|
7 |
\alias{makeCluster}
|
| 56599 |
ripley |
8 |
\alias{makePSOCKcluster}
|
| 56646 |
ripley |
9 |
\alias{makeForkCluster}
|
| 56643 |
ripley |
10 |
\alias{stopCluster}
|
| 57336 |
ripley |
11 |
\alias{setDefaultCluster}
|
| 73712 |
hornik |
12 |
\alias{getDefaultCluster}
|
| 86334 |
luke |
13 |
\alias{registerClusterType}
|
| 66794 |
ripley |
14 |
\alias{R_PARALLEL_PORT}
|
|
|
15 |
|
| 56599 |
ripley |
16 |
\title{
|
|
|
17 |
Create a Parallel Socket Cluster
|
|
|
18 |
}
|
|
|
19 |
\description{
|
|
|
20 |
Creates a set of copies of \R running in parallel and communicating
|
|
|
21 |
over sockets.
|
|
|
22 |
}
|
|
|
23 |
\usage{
|
| 56646 |
ripley |
24 |
makeCluster(spec, type, ...)
|
| 56599 |
ripley |
25 |
makePSOCKcluster(names, ...)
|
| 56646 |
ripley |
26 |
makeForkCluster(nnodes = getOption("mc.cores", 2L), ...)
|
| 56643 |
ripley |
27 |
|
| 57335 |
ripley |
28 |
stopCluster(cl = NULL)
|
|
|
29 |
|
| 57336 |
ripley |
30 |
setDefaultCluster(cl = NULL)
|
| 73712 |
hornik |
31 |
getDefaultCluster()
|
| 87768 |
luke |
32 |
|
|
|
33 |
registerClusterType(type, starter, make.default = FALSE)
|
| 56599 |
ripley |
34 |
}
|
|
|
35 |
\arguments{
|
| 56646 |
ripley |
36 |
\item{spec}{A specification appropriate to the type of cluster.}
|
| 56650 |
hornik |
37 |
\item{names}{Either a character vector of host names on which to run
|
| 57312 |
ripley |
38 |
the worker copies of \R, or a positive integer (in which case
|
| 56599 |
ripley |
39 |
that number of copies is run on \samp{localhost}).}
|
| 57380 |
ripley |
40 |
\item{nnodes}{The number of nodes to be forked.}
|
| 87768 |
luke |
41 |
\item{type}{One of the supported types: see \sQuote{Details}. For
|
|
|
42 |
\code{registerClusterType}, a name for the newly-registered type of
|
|
|
43 |
cluster.}
|
| 56599 |
ripley |
44 |
\item{\dots}{Options to be passed to the function spawning the workers.
|
| 57380 |
ripley |
45 |
See \sQuote{Details}.}
|
| 56644 |
ripley |
46 |
\item{cl}{an object of class \code{"cluster"}.}
|
| 87768 |
luke |
47 |
\item{starter}{A function used for creating a cluster of the appropriate
|
|
|
48 |
\code{type}.}
|
|
|
49 |
\item{make.default}{logical. If \code{TRUE}, the newly-registered cluster
|
|
|
50 |
type will become the default type of cluster created by
|
|
|
51 |
\code{makeCluster}. If \code{FALSE} (the default), the default cluster
|
|
|
52 |
type remains unchanged.}
|
| 56599 |
ripley |
53 |
}
|
|
|
54 |
\details{
|
| 89220 |
luke |
55 |
\code{makeCluster} creates a cluster of one of the registered types.
|
| 56646 |
ripley |
56 |
The default type, \code{"PSOCK"}, calls \code{makePSOCKcluster}. Type
|
| 89220 |
luke |
57 |
\code{"FORK"} calls \code{makeForkCluster}. Other pre-registered
|
|
|
58 |
types are \code{"SOCK"} for \code{makeSOCKcluster} in package
|
|
|
59 |
\CRANpkg{snow}, \code{"MPI"} for \code{makeMPIcluster} in
|
|
|
60 |
\CRANpkg{snow}, \code{"MIRAI"} for \code{make_cluster} in package
|
|
|
61 |
\CRANpkg{mirai}, and \code{"RPSOCK"} for \code{makeClusterPSOCK} in
|
|
|
62 |
package \CRANpkg{parallelly}. Calling \code{registerClusterType} with
|
|
|
63 |
no arguments returns a list of currently registered types.
|
| 61433 |
ripley |
64 |
|
| 66794 |
ripley |
65 |
\code{makePSOCKcluster} is an enhanced version of
|
|
|
66 |
\code{makeSOCKcluster} in package \CRANpkg{snow}. It runs
|
|
|
67 |
\command{Rscript} on the specified host(s) to set up a worker process
|
|
|
68 |
which listens on a socket for expressions to evaluate, and returns the
|
|
|
69 |
results (as serialized objects).
|
| 56599 |
ripley |
70 |
|
| 57378 |
ripley |
71 |
\code{makeForkCluster} is merely a stub on Windows. On Unix-alike
|
|
|
72 |
platforms it creates the worker process by forking.
|
| 61433 |
ripley |
73 |
|
| 56599 |
ripley |
74 |
The workers are most often running on the same host as the master,
|
|
|
75 |
when no options need be set.
|
|
|
76 |
|
| 57378 |
ripley |
77 |
Several options are supported (mainly for \code{makePSOCKcluster}):
|
| 56599 |
ripley |
78 |
\describe{
|
| 57641 |
ripley |
79 |
\item{\code{master}}{The host name of the master, as known to the
|
|
|
80 |
workers. This may not be the same as it is known to the master,
|
|
|
81 |
and on private subnets it may be necessary to specify this as a
|
| 70779 |
ripley |
82 |
numeric IP address. For example, macOS is likely to detect a
|
| 57641 |
ripley |
83 |
machine as \samp{somename.local}, a name known only to itself.}
|
| 56599 |
ripley |
84 |
\item{\code{port}}{The port number for the socket connection,
|
| 56621 |
ripley |
85 |
default taken from the environment variable \env{R_PARALLEL_PORT},
|
| 61974 |
ripley |
86 |
then a randomly chosen port in the range \code{11000:11999}.}
|
| 78800 |
ripley |
87 |
\item{\code{timeout}}{The timeout in seconds for that port. This is
|
|
|
88 |
the maximum time of zero communication between master and worker
|
| 78815 |
ripley |
89 |
before failing. Default is 30 days (and the POSIX standard only
|
| 78800 |
ripley |
90 |
requires values up to 31 days to be supported).}
|
| 74417 |
luke |
91 |
\item{\code{setup_timeout}}{The maximum number of seconds a worker
|
|
|
92 |
attempts to connect to master before failing. Default is 2
|
|
|
93 |
minutes. The waiting time before the next attempt starts at
|
|
|
94 |
0.1 seconds and is incremented 50\% after each retry.}
|
| 57380 |
ripley |
95 |
\item{\code{outfile}}{Where to direct the \code{\link{stdout}} and
|
|
|
96 |
\code{\link{stderr}} connection output from the workers.
|
|
|
97 |
\code{""} indicates no redirection (which may only be useful for
|
| 88512 |
kalibera |
98 |
workers on the local machine; output from workers will not be
|
|
|
99 |
displayed on the \code{Rgui} console in Windows).
|
| 57380 |
ripley |
100 |
Defaults to \file{/dev/null} (\file{nul:} on Windows). The other
|
|
|
101 |
possibility is a file path on the worker's host.
|
|
|
102 |
Files will be opened in append mode, as all workers log to the
|
| 61433 |
ripley |
103 |
same file.}
|
| 78824 |
ripley |
104 |
\item{\code{homogeneous}}{Logical, default true. See \sQuote{Note}.}
|
|
|
105 |
\item{\code{rscript}}{See \sQuote{Note}.}
|
| 65588 |
ripley |
106 |
\item{\code{rscript_args}}{Character vector of additional
|
|
|
107 |
arguments for \command{Rscript} such as \option{--no-environ}.}
|
| 56656 |
ripley |
108 |
\item{\code{renice}}{A numerical \sQuote{niceness} to set for the
|
| 69446 |
ripley |
109 |
worker processes, e.g.\sspace{}\code{15} for a low priority.
|
| 57312 |
ripley |
110 |
OS-dependent: see \code{\link{psnice}} for details.}
|
| 56599 |
ripley |
111 |
\item{\code{rshcmd}}{The command to be run on the master to launch a
|
|
|
112 |
process on another host. Defaults to \command{ssh}.}
|
|
|
113 |
\item{\code{user}}{The user name to be used when communicating with
|
|
|
114 |
another host.}
|
|
|
115 |
\item{\code{manual}}{Logical. If true the workers will need to be
|
| 56646 |
ripley |
116 |
run manually.}
|
| 56649 |
ripley |
117 |
\item{\code{methods}}{Logical. If true (default) the workers will
|
| 57378 |
ripley |
118 |
load the \pkg{methods} package: not loading it saves ca 30\% of the
|
| 65588 |
ripley |
119 |
startup CPU time of the cluster.}
|
| 58219 |
ripley |
120 |
\item{\code{useXDR}}{Logical. If true (default) serialization will
|
| 85908 |
hornik |
121 |
use \I{XDR}: where large amounts of data are to be transferred and
|
| 58219 |
ripley |
122 |
all the nodes are little-endian, communication may be
|
| 65588 |
ripley |
123 |
substantially faster if this is set to false.}
|
| 78806 |
kalibera |
124 |
\item{\code{setup_strategy}}{Character. If \code{"parallel"} (default)
|
|
|
125 |
workers will be started in parallel during cluster setup when this is
|
|
|
126 |
possible, which is now for homogeneous \code{"PSOCK"} clusters with
|
|
|
127 |
all workers started automatically (\code{manual = FALSE}) on the local
|
|
|
128 |
machine. Workers will be started sequentially on other clusters, on
|
| 78815 |
ripley |
129 |
all clusters with \code{setup_strategy = "sequential"} and on \R 3.6.0
|
| 78806 |
kalibera |
130 |
and older. This option is for expert use only (e.g. debugging) and
|
|
|
131 |
may be removed in future versions of R.}
|
| 56599 |
ripley |
132 |
}
|
| 56646 |
ripley |
133 |
|
|
|
134 |
Function \code{makeForkCluster} creates a socket cluster by forking
|
|
|
135 |
(and hence is not available on Windows). It supports options
|
| 58219 |
ripley |
136 |
\code{port}, \code{timeout} and \code{outfile}, and always uses
|
| 75407 |
kalibera |
137 |
\code{useXDR = FALSE}. It is \emph{strongly discouraged} to use the
|
|
|
138 |
\code{"FORK"} cluster with GUI front-ends or multi-threaded libraries.
|
|
|
139 |
#ifdef unix
|
|
|
140 |
See \code{\link{mcfork}} for details.
|
|
|
141 |
#endif
|
| 61433 |
ripley |
142 |
|
| 57378 |
ripley |
143 |
It is good practice to shut down the workers by calling
|
| 87653 |
smeyer |
144 |
\code{stopCluster}: however the workers will terminate
|
| 56630 |
ripley |
145 |
themselves once the socket on which they are listening for commands
|
|
|
146 |
becomes unavailable, which it should if the master \R session is
|
|
|
147 |
completed (or its process dies).
|
| 61433 |
ripley |
148 |
|
| 57336 |
ripley |
149 |
Function \code{setDefaultCluster} registers a cluster as the default one
|
|
|
150 |
for the current session. Using \code{setDefaultCluster(NULL)} removes
|
| 57335 |
ripley |
151 |
the registered cluster, as does stopping that cluster.
|
| 87768 |
luke |
152 |
|
| 89220 |
luke |
153 |
Function \code{registerClusterType} registers a new type of parallel
|
|
|
154 |
cluster in the current session, or lists the registered types. When
|
|
|
155 |
\code{makeCluster} is called with the newly-registered \code{type}, a
|
|
|
156 |
cluster of that type is created using the \code{starter} function.
|
| 56599 |
ripley |
157 |
}
|
| 57380 |
ripley |
158 |
|
| 56599 |
ripley |
159 |
\value{
|
| 73712 |
hornik |
160 |
For the cluster creators, an object of class
|
|
|
161 |
\code{c("SOCKcluster", "cluster")}.
|
|
|
162 |
|
|
|
163 |
For the default cluster setter and getter, the registered default
|
|
|
164 |
cluster or \code{NULL} if there is no such cluster.
|
| 87768 |
luke |
165 |
|
| 89220 |
luke |
166 |
\code{registerClusterType} is invoked for its side effect which is to
|
|
|
167 |
define a mechanism for creating a parallel socket cluster of a given
|
|
|
168 |
named \code{type}. If called without arguments, a character vector of
|
|
|
169 |
registered cluster types.
|
| 56599 |
ripley |
170 |
}
|
| 57380 |
ripley |
171 |
|
| 78815 |
ripley |
172 |
\note{
|
|
|
173 |
Option \code{homogeneous = TRUE} was for years documented as
|
|
|
174 |
\sQuote{Are all the hosts running identical setups?}, but this was
|
| 78822 |
ripley |
175 |
apparently more restrictive than its author intended and not required
|
| 78815 |
ripley |
176 |
by the code.
|
| 87768 |
luke |
177 |
|
| 78815 |
ripley |
178 |
The current interpretation of \code{homogeneous = TRUE} is that
|
|
|
179 |
\command{Rscript} can be launched using the same path on each worker.
|
|
|
180 |
That path is given by the option \code{rscript} and defaults to the
|
|
|
181 |
full path to \command{Rscript} on the master. (The workers are not
|
| 78822 |
ripley |
182 |
required to be running the same version of \R as the master, nor even
|
| 78815 |
ripley |
183 |
as each other.)
|
|
|
184 |
|
|
|
185 |
For \code{homogeneous = FALSE}, \command{Rscript} on the workers is
|
|
|
186 |
found on their default shell's path.
|
| 87768 |
luke |
187 |
|
| 78815 |
ripley |
188 |
For the very common usage of running both master and worker on a
|
|
|
189 |
single multi-core host, the default settings are the appropriate ones.
|
| 84480 |
ripley |
190 |
|
|
|
191 |
A socket \link{connection} is used to communicate from the master to
|
|
|
192 |
each worker so the maximum number of connections (default 128 but some
|
|
|
193 |
will be in use) may need to be increased when the master process is
|
| 87768 |
luke |
194 |
started.
|
| 78815 |
ripley |
195 |
}
|
|
|
196 |
|
| 56742 |
ripley |
197 |
\author{
|
|
|
198 |
Luke Tierney and R Core.
|
| 56599 |
ripley |
199 |
|
| 57939 |
hornik |
200 |
Derived from the \CRANpkg{snow} package.
|
| 56742 |
ripley |
201 |
}
|