# NOT RUN {
message(paste("Number of cores available:", availableCores()))
# }
# NOT RUN {
options(mc.cores = 2L)
message(paste("Number of cores available:", availableCores()))
# }
# NOT RUN {
# }
# NOT RUN {
## IMPORTANT: availableCores() may return 1L
options(mc.cores = 1L)
ncores <- max(1, availableCores() - 1)
message(paste("Number of cores to use:", ncores))
# }
# NOT RUN {
# }
# NOT RUN {
## Use 75% of the cores on the system but never more than four
options(parallelly.availableCores.custom = function() {
ncores <- max(parallel::detectCores(), 1L, na.rm = TRUE)
min(0.75 * ncores, 4L)
})
message(paste("Number of cores available:", availableCores()))
## What is available minus one core but at least one
options(parallelly.availableCores.custom = function() {
max(1L, parallelly::availableCores() - 1L)
})
message(paste("Number of cores available:", availableCores()))
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab