R/MA.parallel.R

Defines functions endparallel beginparallel

beginparallel <- function(parallel = 1,
           type = "MPI",
           seed = NULL,
           packagenames = c("RDS"),
           verbose = TRUE) {
    ### Snow commands to set up cluster
    cl <- parallel::makeCluster(parallel, type = type)
    ### initialize parallel random number streams
    if (is.null(seed)) {
      parallel::clusterSetRNGStream(cl)
    } else{
      parallel::clusterSetRNGStream(cl, iseed = seed)
    }
    ### start each virtual machine with libraries loaded
    for (pkg in packagenames) {
      attached <-
        parallel::clusterCall(cl,
                              require,
                              package = pkg,
                              character.only = TRUE)
    }
    return(cl)
  }

endparallel <- function(cl,
                        type = "MPI",
                        finalize = FALSE,
                        verbose = TRUE) {
  parallel::stopCluster(cl)
  invisible()
}

Try the RDS package in your browser

Any scripts or data that you put into this service are public.

RDS documentation built on Dec. 2, 2017, 1:08 a.m.