Skip to content

Commit

Permalink
Reduce workers during R CMD CHECK if required
Browse files Browse the repository at this point in the history
  • Loading branch information
HDash committed Dec 4, 2024
1 parent bf2fb09 commit ab31f80
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
24 changes: 16 additions & 8 deletions R/set_cores.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#' Set cores
#'
#' Assign cores automatically for parallel processing, while reserving some.
#'
#'
#' @param workers Number (>1) or proportion (<1) of worker cores to use.
#' @param verbose Print messages.
#' @param progressbar logical(1) Enable progress bar
#' @param progressbar logical(1) Enable progress bar
#' (based on \code{plyr:::progress_text}).
#' Enabling the progress bar changes the default value of tasks to
#' \code{.Machine$integer.max}, so that progress is reported for
#' Enabling the progress bar changes the default value of tasks to
#' \code{.Machine$integer.max}, so that progress is reported for
#' each element of X.
#' @returns List of core allocations.
#'
#'
#' @export
#' @import data.table
#' @import BiocParallel
#' @importFrom parallel detectCores
set_cores <- function(workers = .90,
progressbar = TRUE,
verbose = TRUE) {
verbose = TRUE) {

# Enable parallelization of HDF5 functions
## Allocate ~10% of your available cores to non-parallelized processes
workers <- if (is.null(workers)) .90 else workers
Expand All @@ -36,12 +36,20 @@ set_cores <- function(workers = .90,
)
### Ensure data.table doesn't interfere with parallelization ####
if(workers>1) data.table::setDTthreads(threads = 1)
### Handle _R_CHECK_LIMIT_CORES_ ###
if (nzchar(chk <- Sys.getenv("_R_CHECK_LIMIT_CORES_", ""))) {
if (workers > 2) {
workers <- 2
messager(paste("R_CHECK_LIMIT_CORES_' environment variable detected",
"BiocParallel workers reduced to 2."))
}
}
#### Handle Windows ####
if (.Platform$OS.type == "windows") {
params <- BiocParallel::SnowParam(workers = workers,
progressbar = progressbar)
} else {
params <- BiocParallel::MulticoreParam(workers = workers,
params <- BiocParallel::MulticoreParam(workers = workers,
progressbar = progressbar)
}
# DelayedArray::setAutoBPPARAM(params)
Expand Down
6 changes: 3 additions & 3 deletions man/set_cores.Rd

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

0 comments on commit ab31f80

Please sign in to comment.