The registerDoParallel function is used to register the parallel backend with the foreach package.





A cluster object as returned by makeCluster, or the number of nodes to be created in the cluster. If not specified, on Windows a three worker cluster is created and used.


The number of cores to use for parallel execution. If not specified, the number of cores is set to the value of options("cores"), if specified, or to one-half the number of cores detected by the parallel package.


Package options. Currently, only the nocompile option is supported. If nocompile is set to TRUE, compiler support is disabled.


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.


cl <- makePSOCKcluster(2)
m <- matrix(rnorm(9), 3, 3)
foreach(i=1:nrow(m), .combine=rbind) 

Want to suggest features or report bugs for Use the GitHub issue tracker.

comments powered by Disqus