Skip to content

Commit ad05432

Browse files
author
luke
committed
Add documentation chenges from PR18587.
git-svn-id: https://svn.r-project.org/R/trunk@87768 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent b98a660 commit ad05432

File tree

3 files changed

+181
-11
lines changed

3 files changed

+181
-11
lines changed

src/library/parallel/R/snow.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# File src/library/parallel/R/snow.R
22
# Part of the R package, https://www.R-project.org
33
#
4-
# Copyright (C) 1995-2021 The R Core Team
4+
# Copyright (C) 1995-2025 The R Core Team
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by

src/library/parallel/man/makeCluster.Rd

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
% File src/library/parallel/man/makePSOCKcluster.Rd
1+
% File src/library/parallel/man/makeCluster.Rd
22
% Part of the R package, https://www.R-project.org
3-
% Copyright 2003-2023 R Core Team
3+
% Copyright 2003-2025 R Core Team
44
% Distributed under GPL 2 or later
55

66
\name{makeCluster}
77
\alias{makeCluster}
88
\alias{makePSOCKcluster}
99
\alias{makeForkCluster}
1010
\alias{stopCluster}
11-
\alias{closeNode}
12-
\alias{recvData}
13-
\alias{recvOneData}
14-
\alias{sendData}
1511
\alias{setDefaultCluster}
1612
\alias{getDefaultCluster}
1713
\alias{registerClusterType}
@@ -33,17 +29,27 @@ stopCluster(cl = NULL)
3329

3430
setDefaultCluster(cl = NULL)
3531
getDefaultCluster()
32+
33+
registerClusterType(type, starter, make.default = FALSE)
3634
}
3735
\arguments{
3836
\item{spec}{A specification appropriate to the type of cluster.}
3937
\item{names}{Either a character vector of host names on which to run
4038
the worker copies of \R, or a positive integer (in which case
4139
that number of copies is run on \samp{localhost}).}
4240
\item{nnodes}{The number of nodes to be forked.}
43-
\item{type}{One of the supported types: see \sQuote{Details}.}
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.}
4444
\item{\dots}{Options to be passed to the function spawning the workers.
4545
See \sQuote{Details}.}
4646
\item{cl}{an object of class \code{"cluster"}.}
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.}
4753
}
4854
\details{
4955
\code{makeCluster} creates a cluster of one of the supported types.
@@ -137,6 +143,11 @@ getDefaultCluster()
137143
Function \code{setDefaultCluster} registers a cluster as the default one
138144
for the current session. Using \code{setDefaultCluster(NULL)} removes
139145
the registered cluster, as does stopping that cluster.
146+
147+
Function \code{registerClusterType} registers a new type of parallel cluster
148+
in the current session. When \code{makeCluster} is called with the
149+
newly-registered \code{type}, a cluster of that type is created using the
150+
\code{starter} function.
140151
}
141152
142153
\value{
@@ -145,14 +156,18 @@ getDefaultCluster()
145156
146157
For the default cluster setter and getter, the registered default
147158
cluster or \code{NULL} if there is no such cluster.
159+
160+
\code{registerClusterType} is invoked for its side effect which is to define
161+
a mechanism for creating a parallel socket cluster of a given named
162+
\code{type}.
148163
}
149164
150165
\note{
151166
Option \code{homogeneous = TRUE} was for years documented as
152167
\sQuote{Are all the hosts running identical setups?}, but this was
153168
apparently more restrictive than its author intended and not required
154169
by the code.
155-
170+
156171
The current interpretation of \code{homogeneous = TRUE} is that
157172
\command{Rscript} can be launched using the same path on each worker.
158173
That path is given by the option \code{rscript} and defaults to the
@@ -162,14 +177,14 @@ getDefaultCluster()
162177
163178
For \code{homogeneous = FALSE}, \command{Rscript} on the workers is
164179
found on their default shell's path.
165-
180+
166181
For the very common usage of running both master and worker on a
167182
single multi-core host, the default settings are the appropriate ones.
168183

169184
A socket \link{connection} is used to communicate from the master to
170185
each worker so the maximum number of connections (default 128 but some
171186
will be in use) may need to be increased when the master process is
172-
started.
187+
started.
173188
}
174189

175190
\author{
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
% File src/library/parallel/man/sendData.Rd
2+
% Part of the R package, https://www.R-project.org
3+
% Copyright 2003-2025 R Core Team
4+
% Distributed under GPL 2 or later
5+
6+
\name{sendData}
7+
\alias{closeNode}
8+
\alias{recvData}
9+
\alias{recvOneData}
10+
\alias{sendData}
11+
\title{Cluster Back-end Interface}
12+
\description{
13+
The communication primitives used by the \pkg{parallel} package to
14+
handle the state and communicate with nodes in the clusters.
15+
}
16+
\usage{
17+
sendData(node, data)
18+
recvData(node)
19+
recvOneData(cl)
20+
closeNode(node)
21+
}
22+
\arguments{
23+
\item{cl}{
24+
The cluster object, visible to the user. Should be a list inheriting
25+
from class \code{cluster}, containing the node objects.
26+
}
27+
\item{node}{
28+
The node object corresponding to one execution unit inside the
29+
cluster.
30+
}
31+
\item{data}{
32+
The data structure containing a message to the node.
33+
}
34+
}
35+
\details{
36+
A \code{`[.cluster`} method is provided, which retains the classes of the
37+
cluster when subset. The cluster back-end should either rely on this method or
38+
supply its own method that also invokes this method through \code{NextMethod}
39+
or calls \code{.subset} directly.
40+
41+
The \code{data} messages sent to the nodes are lists containing the
42+
following elements: \describe{
43+
\item{type}{
44+
A short string describing the type of packet: \describe{
45+
\item{DONE}{
46+
Sent by the default \code{stopCluster} implementation before
47+
calling \code{closeNode}.
48+
}
49+
\item{EXEC}{
50+
The packet contains a job to execute.
51+
}
52+
}
53+
}
54+
\item{value}{
55+
For messages of type \dQuote{EXEC}, a list with the following
56+
elements: \describe{
57+
\item{fun}{
58+
The function to execute.
59+
}
60+
\item{args}{
61+
The arguments for \code{fun} above as a list.
62+
}
63+
\item{return}{
64+
Defaults to \code{TRUE}. Not currently used by \pkg{parallel}.
65+
}
66+
\item{tag}{
67+
The same tag must be returned back from the worker. Used to
68+
identify individual elements of a larger job when using
69+
dynamic load balancing.
70+
}
71+
}
72+
}
73+
}
74+
75+
If the \dQuote{DONE} messages are used (for example when calling
76+
\code{stopCluster.default}), the node can close the connection upon
77+
receipt.
78+
79+
The response to an \dQuote{EXEC} message that should be returned by
80+
\code{recvData} is a list with the following elements: \describe{
81+
\item{type}{A string, \code{"VALUE"}.}
82+
\item{value}{
83+
The value of \code{do.call(fun, args, quote = TRUE)}. If the
84+
evaluation raised an error, the value of the error.
85+
}
86+
\item{success}{
87+
A logical scalar indicating whether the evaluation completed
88+
without raising an error.
89+
}
90+
\item{time}{
91+
The time it took to complete the job, an object of class
92+
\code{proc_time}. Can be obtained using
93+
\code{\link[base]{system.time}} or by subtracting outputs of
94+
\code{\link[base]{proc.time}}.
95+
}
96+
\item{tag}{
97+
The original \code{tag} from the \dQuote{EXEC} message.
98+
}
99+
}
100+
101+
\code{recvData} can block if the job is not yet complete, and
102+
\code{recvOneData} should block until at least one node is able to
103+
return a complete job result.
104+
105+
The default \code{closeNode} method does nothing. It is envisaged that
106+
\code{stopCluster} is used to shut down the entire cluster, although other
107+
back-ends may use this to implement node-specific logic.
108+
}
109+
\value{
110+
\item{sendData}{
111+
Ignored. Called for the side effect of sending the \code{data} to the
112+
node.
113+
}
114+
\item{recvData}{
115+
The result of the job previously submitted to the node.
116+
}
117+
\item{recvOneData}{
118+
A list with the following items: \describe{
119+
\item{node}{The index of the node returning the data.}
120+
\item{value}{The result of \code{recvData(cluster[[node]])}.}
121+
}
122+
}
123+
\item{closeNode}{
124+
Ignored. Called for the side effect of cleaning up the connection to
125+
the node.
126+
}
127+
}
128+
\seealso{
129+
\code{\link{stopCluster}} should also be implemented, but is a user
130+
interface and documented separately. The default method will post
131+
termination messages to individual nodes and then call
132+
\code{closeNode} on them.
133+
}
134+
\examples{\dontrun{
135+
# A toy cluster consisting of one connection.
136+
sendData.mynode <- function(node, data) serialize(data, node)
137+
recvData.mynode <- function(node) unserialize(node)
138+
recvOneData.mycluster <- function(cl) list(
139+
node = 1, value = recvData(cl[[1]])
140+
)
141+
closeNode.mynode <- function(node) close(node)
142+
143+
# Not shown: R starting a serverSocket on the other end, ready to
144+
# accept connections and evaluate jobs
145+
cl <- structure(list(
146+
structure(
147+
socketConnection(..., blocking = TRUE, open = 'a+b'),
148+
class = 'mynode'
149+
)
150+
), class = c('mycluster', 'cluster'))
151+
clusterEvalQ(cl, Sys.getpid())
152+
stopCluster(cl)
153+
rm(cl)
154+
}}
155+
\keyword{internal}

0 commit comments

Comments
 (0)