Interface for parallel computations
An interface to apply some function fn in parallel on columns of a matrix. dopar is used internally in spaMM, but is not logically restricted to mixed-effect applications, hence it can be used more widely. Depending on the nb_cores argument, parallel or serial computation is performed. A socket cluster is used by default for parallel computations, but a fork cluster can be requested on linux and alike operating systems by using argument cluster_args=list(type="FORK").
dopar(newresp, fn, nb_cores = NULL, fit_env, control = list(),
cluster_args = NULL, debug. = FALSE, iseed = NULL,
showpbar = eval(spaMM.getOption("barstyle")),
pretest_cores =NULL, ...)newresp |
A matrix on whose columns |
fn |
Function, whose first argument is named |
nb_cores |
Integer. Number of cores to use for parallel computations. If >1, a cluster of |
fit_env |
(for socket clusters only:) An environment, or a list, containing variables to be exported on the nodes of the cluster (by |
control |
A list following the
|
cluster_args |
A list of arguments passed to |
debug. |
(for socket clusters only:) For debugging purposes. Effect, if any, is to be defined by the |
iseed |
(all parallel contexts:) Integer, or NULL. If an integer, it is used as the |
showpbar |
(for socket clusters only:) Controls display of progress bar. See |
pretest_cores |
(for socket clusters only:) A function to run on the cores before running |
... |
Further arguments to be passed (unevaluated) to |
Control of random numbers through the "L'Ecuyer-CMRG" generator and the iseed argument is not sufficient for consistent results when the doSNOW parallel backend is used, so if you really need such control in a fn using random numbers, do not use doSNOW. Yet, it is fine to use doSNOW for bootstrap procedures in spaMM, because the fitting functions do not use random numbers: only sample simulation uses them, and it is not performed in parallel.
The result of calling foreach, pbapply or mclapply, 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: a default "=" character for fork clusters, and otherwise"P" for parallel computation via foreach and doSNOW, "p" for parallel computation via pbapply, and "s" for serial computation via pbapply.
dofuture for an alternative implementation of (essentially) the same functionalities, and wrap_parallel for its differences from dopar.
## See source code of spaMM_boot()
## Not run:
# Useless function, but requiring some argument beyond the first
foo <- function(y, somearg, ...) {
if ( is.null(somearg) || TRUE ) length(y)
}
# Whether FORK can be used depends on OS and whether Rstudio is used:
dopar(matrix(1,ncol=4,nrow=3), foo, fit_env=list(), somearg=NULL,
nb_cores=2, cluster_args=list(type="FORK"))
## End(Not run)Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.