tests/testthat/test-parallelisation.R

#library("Infusion")
enorm <- function() {Sys.sleep(1); c(r=rnorm(n=1,mean = 0,s=1))}
                                                                         # no more than 2 cores in R checks...
add_reftable(Simulate=enorm, par.grid=data.frame(matrix(ncol=0,nrow=3)), nb_cores=2, cl_seed=123)  # replicable
add_reftable(Simulate=enorm, par.grid=data.frame(matrix(ncol=0,nrow=3)), nb_cores=2, cl_seed=123)  # replicable
if (.Platform$OS.type != "windows") {
  add_reftable(Simulate=enorm, par.grid=data.frame(matrix(ncol=0,nrow=8)), nb_cores=2, cl_seed=123, cluster_args=list(type="FORK"))  # replicable
  add_reftable(Simulate=enorm, par.grid=data.frame(matrix(ncol=0,nrow=8)), nb_cores=2, cl_seed=123, cluster_args=list(type="FORK"))  # replicable
  if (suppressWarnings(do.call("require",list(package="progressr", quietly = TRUE)))) {
    add_reftable(Simulate=enorm, par.grid=data.frame(matrix(ncol=0,nrow=8)), nb_cores=2, cl_seed=123, cluster_args=list(type="FORK"))  # replicable
    add_reftable(Simulate=enorm, par.grid=data.frame(matrix(ncol=0,nrow=8)), nb_cores=2, cl_seed=123, cluster_args=list(type="FORK"))  # replicable
    unloadNamespace("progressr")
  } else {message(paste("'progressr' required but not available.",sep=""))}
}


if (FALSE) {
  # template for devel 
  xs <- 1:8
  with_progress({
    p <- progressor(steps=4)
    yyy <- parallel::mclapply(xs, function(x) {
      res <- enorm()
      p()
      res
    }, mc.cores=2, mc.preschedule = FALSE)
  })
  str(unlist(yyy,use.names = FALSE))
}

Try the Infusion package in your browser

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

Infusion documentation built on May 3, 2023, 5:10 p.m.