Skip to content

Commit

Permalink
start parallel comp with subRNG increments
Browse files Browse the repository at this point in the history
  • Loading branch information
philchalmers committed Jul 27, 2024
1 parent 9aecd76 commit 3cbc7a9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
20 changes: 20 additions & 0 deletions R/runArraySimulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@
#' to. If omitted the files will be stored in the same working directory
#' where the script was submitted
#'
#' @param parallel logical; use parallel computations via the a "SOCK" cluster?
#' Only use when the instruction shell file requires more than 1 core
#' (number of cores detected via \code{ncores})
#'
#' @param cl cluster definition. If omitted a "SOCK" cluster will be defined
#'
#' @param ncores number of cores to use when \code{parallel=TRUE}. Note that
#' the default uses 1 minus the number of available cores, therefore this
#' will only be useful when \code{ncores > 2} as defined in the shell instruction
#' file
#'
#' @param filename_suffix suffix to add to the \code{filename};
#' default add '-' with the \code{arrayID}
#'
Expand Down Expand Up @@ -222,6 +233,8 @@ runArraySimulation <- function(design, ..., replications,
arrayID = getArrayID(),
filename_suffix = paste0("-", arrayID),
addArrayInfo = TRUE,
parallel = FALSE, cl = NULL,
ncores = parallel::detectCores() - 1L,
save_details = list(),
control = list()){
dots <- list(...)
Expand Down Expand Up @@ -254,13 +267,20 @@ runArraySimulation <- function(design, ..., replications,
filename <- gsub("//", "/", filename)
}
save_details$arrayID <- arrayID
if(parallel){
if(is.null(cl)){
cl <- parallel::makeCluster(ncores, type="SOCK")
on.exit(parallel::stopCluster(cl), add=TRUE)
}
}
seed <- genSeeds(design, iseed=iseed, arrayID=arrayID)
dsub <- design[arrayID, , drop=FALSE]
attr(dsub, 'Design.ID') <- attr(design, 'Design.ID')[arrayID]

ret <- runSimulation(design=dsub, replications=replications,
filename=filename, seed=seed,
verbose=FALSE, save_details=save_details,
parallel=parallel, cl=cl,
control=control, save=FALSE, ...)
if(addArrayInfo && (is.null(dots$store_results) ||
(!is.null(dots$store_results) && isTRUE(dots$store_results)))){
Expand Down
2 changes: 1 addition & 1 deletion R/runSimulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
#' \item{\code{allow_nan}}{logical (default is \code{FALSE}); should \code{NaN}s be allowed in the
#' analyse step as a valid result from the simulation analysis?}
#'
#' \item{\code{type}}{default type of cluster to create for the \code{cl} object if no supplied.
#' \item{\code{type}}{default type of cluster to create for the \code{cl} object if not supplied.
#' For Windows OS this defaults to \code{"PSOCK"}, otherwise \code{"SOCK"} is selected
#' (suitable for Linux and Mac OSX). This is ignored if the user specifies their own \code{cl} object}
#'
Expand Down
14 changes: 14 additions & 0 deletions man/runArraySimulation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/runSimulation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3cbc7a9

Please sign in to comment.