registerDoParallel {doParallel} | R Documentation |
registerDoParallel
Description
The registerDoParallel
function is used to register the
parallel backend with the foreach
package.
Usage
registerDoParallel(cl, cores=NULL, ...)
stopImplicitCluster()
Arguments
cl |
A cluster object as returned by |
cores |
The number of cores to use for parallel execution. If not
specified, the number of cores is set to the value of
|
... |
Package options. Currently, only the |
Details
The parallel
package from R 2.14.0 and later provides functions for
parallel execution of R code on machines with multiple cores or processors
or multiple computers. It is essentially a blend of the snow
and
multicore
packages. By default, the doParallel
package uses
snow
-like functionality. The snow
-like functionality
should work fine on Unix-like systems, but the multicore
-like
functionality is limited to a single sequential worker on Windows systems.
On workstations with multiple cores running Unix-like operating systems,
the system fork
call is used to spawn copies of the current process.
The doParallel
backend supports both multicore and snow options passed
through the foreach
function.
The supported multicore options are preschedule
, set.seed
,
silent
, and cores
, which are analogous to the similarly named
arguments to mclapply
, and are passed using the
.options.multicore
argument to foreach
. The supported snow options are
preschedule
, which like its multicore analog can be used to chunk the
tasks so that each worker gets a prescheduled chunk of tasks, and
attachExportEnv
, which can be used to attach the export environment
in certain cases where R's lexical scoping is unable to find a needed
export. The snow options are passed to foreach
using the .options.snow
argument.
The function stopImplicitCluster
can be used in vignettes and other places
where it is important to explicitly close the implicitly created cluster.
Examples
cl <- makePSOCKcluster(2)
registerDoParallel(cl)
m <- matrix(rnorm(9), 3, 3)
foreach(i=1:nrow(m), .combine=rbind)
stopCluster(cl)