dofuture function

Interface for parallel computations

Interface for parallel computations

interface to apply some function fn in parallel on columns of a matrix. It 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, calling the future.apply::future_apply function. 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").

dofuture(newresp, fn, nb_cores=NULL, fit_env, control=list(), cluster_args=NULL, debug.=FALSE, iseed=NULL, showpbar="ignored", pretest_cores="ignored", ... )

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); or an integer, then converted to a trivial matrix matrix(seq(newresp),ncol=newresp,nrow=1).
  • fn: Function whose first argument is named y. The function will be applied for y taken to be 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: (for socket clusters only:) An environment, or a list, containing variables to be exported on the nodes of the cluster (by parallel::clusterExport).
  • control: A list. The only effective control is .combine="rbind" (mimicking the foreach syntax used in the alternative interface dopar).
  • cluster_args: A list of arguments passed to parallel::makeCluster or parallel::makeForkCluster. E.g., outfile="log.txt" may be useful to collect output from the nodes, and type="FORK" to force a fork cluster on linux(-alikes).
  • debug.: (for socket clusters only:) 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, it is used to initialize "L'Ecuyer-CMRG" random-number generator (iseed argument of clusterSetRNGStream), with identical effect across different models of parallelisation. If iseed is NULL, the seed is not controlled.
  • showpbar,pretest_cores: Currently ignored; for consistency with dopar formal arguments.
  • ...: Further arguments to be passed (unevaluated) to future.apply (and then possibly to fn).

Returns

The result of calling future.apply. If the progressr package is loaded, a side-effect of dofuture is to show a progress bar with character 'S' or 'P' or 'F' depending on parallelisation status (serial/socket/fork).

See Also

dopar for an alternative implementation of (essentially) the same functionalities, and wrap_parallel for its differences from dofuture.

Examples

## Not run: if (requireNamespace("future.apply", quietly = TRUE)) { # 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: dofuture(matrix(1,ncol=4,nrow=3), foo, fit_env=list(), somearg=NULL, nb_cores=2, cluster_args=list(type="FORK")) } ## End(Not run)
  • Maintainer: François Rousset
  • License: CeCILL-2
  • Last published: 2024-06-09