Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/library/parallel/R/snow.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,42 @@ setDefaultClusterOptions <- function(...) {

clusterStarters <- new.env()
registerClusterType <- function(type, starter, make.default = FALSE) {
if (missing(type))
return(as.list(clusterStarters))
if (exists(type, clusterStarters))
warning(sprintf("replacing registration for cluster type '%s'", type))
assign(type, starter, clusterStarters)
if (make.default)
setDefaultClusterOptions(type = type)
}

initRegisterClusterTypes <- function() {
## Register PSOCK and FORK to be listed by registerClusterType()
registerClusterType("PSOCK", function(spec, ...)
makePSOCKcluster(names = spec, ...))

registerClusterType("FORK", function(spec, ...)
makeForkCluster(nnodes = spec, ...))

registerClusterType("SOCK", function(spec, ...)
snow::makeSOCKcluster(names = spec, ...))

registerClusterType("MPI", function(spec, ...)
snow::makeMPIcluster(count = spec, ...))

registerClusterType("MIRAI", function(spec, ...)
mirai::make_cluster(n = spec, ...))

registerClusterType("RPSOCK", function(spec, ...)
parallelly::makeClusterPSOCK(workers = spec, ...))
}

makeCluster <-
function (spec, type = getClusterOption("type"), ...)
{
switch(type,
PSOCK = makePSOCKcluster(names = spec, ...),
FORK = makeForkCluster(nnodes = spec, ...),
SOCK = snow::makeSOCKcluster(names = spec, ...),
MPI = snow::makeMPIcluster(count = spec, ...),
MIRAI = mirai::make_cluster(n = spec, ...),
RPSOCK = parallelly::makeClusterPSOCK(workers = spec, ...),
## NWS = snow::makeNWScluster(names = spec, ...),
if (exists(type, clusterStarters))
get(type, clusterStarters)(spec, ...)
else stop(sprintf("unknown cluster type: '%s'", type)))
Expand Down
2 changes: 2 additions & 0 deletions src/library/parallel/R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ if (.Platform$OS.type == "windows")

.onLoad <- function(libname, pkgname)
{
initRegisterClusterTypes()
initDefaultClusterOptions(libname)

cores <- getOption("mc.cores", NULL)
if(is.null(cores) && !is.na(nc <- as.integer(Sys.getenv("MC_CORES"))))
options("mc.cores" = nc)
Expand Down
23 changes: 14 additions & 9 deletions src/library/parallel/man/makeCluster.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ registerClusterType(type, starter, make.default = FALSE)
\item{nnodes}{The number of nodes to be forked.}
\item{type}{One of the supported types: see \sQuote{Details}. For
\code{registerClusterType}, a name for the newly-registered type of
cluster.}
cluster, or missing.}
\item{\dots}{Options to be passed to the function spawning the workers.
See \sQuote{Details}.}
\item{cl}{an object of class \code{"cluster"}.}
Expand All @@ -52,10 +52,14 @@ registerClusterType(type, starter, make.default = FALSE)
type remains unchanged.}
}
\details{
\code{makeCluster} creates a cluster of one of the supported types.
The default type, \code{"PSOCK"}, calls \code{makePSOCKcluster}. Type
\code{"FORK"} calls \code{makeForkCluster}. Other types are passed to
package \CRANpkg{snow}.
\code{makeCluster} creates a cluster of one of the registered types in
\code{names(registerClusterType())}. The default type, \code{"PSOCK"},
calls \code{makePSOCKcluster}. Type \code{"FORK"} calls
\code{makeForkCluster}. Other pre-registered types are \code{"SOCK"}
for \code{makeSOCKcluster} in package \CRANpkg{snow}, \code{"MPI"} for
\code{makeMPIcluster} in \CRANpkg{snow}, \code{"MIRAI"} for
\code{make_cluster} in package \CRANpkg{mirai}, and \code{"RPSOCK"}
for \code{makeClusterPSOCK} in package \CRANpkg{parallelly}.

\code{makePSOCKcluster} is an enhanced version of
\code{makeSOCKcluster} in package \CRANpkg{snow}. It runs
Expand Down Expand Up @@ -146,9 +150,9 @@ registerClusterType(type, starter, make.default = FALSE)
the registered cluster, as does stopping that cluster.

Function \code{registerClusterType} registers a new type of parallel cluster
in the current session. When \code{makeCluster} is called with the
newly-registered \code{type}, a cluster of that type is created using the
\code{starter} function.
in the current session or lists registered types. When \code{makeCluster} is
called with the newly-registered \code{type}, a cluster of that type is
created using the \code{starter} function.
}

\value{
Expand All @@ -160,7 +164,8 @@ registerClusterType(type, starter, make.default = FALSE)

\code{registerClusterType} is invoked for its side effect which is to define
a mechanism for creating a parallel socket cluster of a given named
\code{type}.
\code{type}. If called without arguments, a named list of registered cluster
starter functions.
}

\note{
Expand Down
Loading