Learn R Programming

spaMM (version 3.2.0)

dopar: Interface for parallel computations

Description

An interface to apply some function fn in parallel on columns of a matrix. Depending on the nb_cores argument, parallel or serial computation is performed, and depending whether the doSNOW package is attached, foreach or pbapply is called (doSNOW allows more efficient load balancing than pbapply). It wraps these calls, handling all cluster management. It is used internally in spaMM, but is not logically restricted to mixed-effect applications, hence it can be used more widely.

Usage

dopar(newresp, fn, nb_cores = NULL, fit_env, control = list(), 
      cluster_args = NULL, debug. = FALSE, iseed = NULL, ...)

Arguments

newresp

A matrix on whose columns fn will be applied (e.g., as used internally in spaMM, the return value of a simulate.HLfit() call).

fn

Function, whose first argument is named y, to be applied to each column of newresp.

nb_cores

Integer. Number of cores to use for parallel computations. If >1, a cluster of nb_cores nodes is used. Otherwise, no parallel computation is performed.

fit_env

A environment, or a list, containing variables to be exported on the nodes of the cluster (by parallel::clusterExport).

control

A list. In particular if the doSNOW package is attached, foreach is called with default arguments including i = 1:ncol(newresp), .combine = "cbind", .inorder = TRUE, .errorhandling = "remove", .packages = "spaMM". control may be used to provide non-default values of these arguments. For example, .errorhandling = "pass" is useful to get error messages from the nodes. If doSNOW is not attached, the result is still in the format returned by foreach with default .combine="cbind" or possible non-default .combine="rbind".

cluster_args

A list of arguments passed to parallel::makeCluster. E.g., outfile="log.txt" may be useful to collect output from the nodes.

debug.

For debugging purposes. Effect, if any, is to be defined by the fn as provided by the user.

iseed

Integer, or NULL. If an integer, parallel::clusterSetRNGStream(cl = cl, iseed) is called, setting and initializing "L'Ecuyer-CMRG" random-number generator on the nodes. This is useful if random numbers are used on the nodes (see clusterSetRNGStream). If iseed is NULL, the default generator is selected on each node, where its seed is not controlled.

Further arguments to be passed (unevaluated) to fn.

Value

The result of calling foreach or pbapply, as dependent on the control argument. A side-effect of dopar is to show a progress bar that informs about the type of parallelisation performed: "P" for parallel computation via foreach and doSNOW, "p" for parallel computation via pbapply, "s" for serial computation via pbapply.

Examples

Run this code
# NOT RUN {
## See source code of spaMM_boot()
# }

Run the code above in your browser using DataLab