diff --git a/R/netsim_scenarios.R b/R/netsim_scenarios.R index 64531cd..778d484 100644 --- a/R/netsim_scenarios.R +++ b/R/netsim_scenarios.R @@ -3,6 +3,10 @@ #' This step template is similar to `netsim_scenarios` but for the HPC. It uses #' `slurmworkflow::step_tmpl_map` internally and should be used as any #' `slurmworkflow` step. For details, see `netsim_scenarios` documentation. +#' The inner parallelization is by default handled with +#' `future::plan("multicore", workers = n_cores)`. +#' Using `control$future.use.plan <- future::tweaked()` will bypass +#' this setting. #' #' @inheritParams slurmworkflow::step_tmpl_map #' @inheritParams netsim_scenarios @@ -17,6 +21,13 @@ step_tmpl_netsim_scenarios <- function(path_to_x, param, init, control, output_dir, libraries = NULL, setup_lines = NULL, max_array_size = NULL, ...) { + + # Set a `multicore` plan with `n_cores` workers by default. + # Bypassed if `control$future.use.plan` is manually set + if (!inherits(control$future.use.plan, c("tweaked", "future"))) { + control$future.use.plan <- future::tweak("multicore", workers = n_cores) + } + p_list <- netsim_scenarios_setup( path_to_x, param, init, control, scenarios_list, n_rep, n_cores, @@ -95,6 +106,14 @@ netsim_scenarios_setup <- function(path_to_x, param, init, control, batchs_list <- rep(seq_len(n_batch), length(scenarios_list)) scenarios_list <- rep(scenarios_list, each = n_batch) + if (isTRUE(control$future.use.plan)) { + stop( + "`netsim_scenarios` do not accept `control$future.use.plan == TRUE`.\n", + "use `control$future.use.plan = future::tweak()` \n", + " to setup a custom ." + ) + } + list( scenarios_list = scenarios_list, batchs_list = batchs_list, @@ -430,4 +449,4 @@ get_scenarios_tibble_infos <- function(scenario_dir) { file_path = file_name_list, scenario_name = parts[, "scenario"] ) -} \ No newline at end of file +} diff --git a/man/step_tmpl_netsim_scenarios.Rd b/man/step_tmpl_netsim_scenarios.Rd index 6ffebcc..2d5790f 100644 --- a/man/step_tmpl_netsim_scenarios.Rd +++ b/man/step_tmpl_netsim_scenarios.Rd @@ -45,9 +45,11 @@ required for the model to run. (e.g. EpiModelHIV or EpiModelCOVID)} \item{setup_lines}{(optional) a vector of bash lines to be run first. This can be used to load the required modules (like R, python, etc).} -\item{max_array_size}{maximum number of array jobs to be submitted at the -same time. Should be strictly less than the maximum number of jobs you are -allowed to submit to slurm on your HPC.} +\item{max_array_size}{maximum number of array jobs to be submitted at once. +It should be strictly less than the maximum number of jobs you are allowed +to submit to \code{slurm} on your HPC. If the number of jobs is greater than +\code{max_array_size}, they will be submitted in multiple batches. The +submission of the next batch is automatically handled by \code{slurmworkflow}.} \item{...}{arguments to vectorize over (vectors or lists of strictly positive length, or all of zero length). See also ‘Details’.} @@ -59,6 +61,10 @@ a template function to be used by \code{add_workflow_step} This step template is similar to \code{netsim_scenarios} but for the HPC. It uses \code{slurmworkflow::step_tmpl_map} internally and should be used as any \code{slurmworkflow} step. For details, see \code{netsim_scenarios} documentation. +The inner parallelization is by default handled with +\code{future::plan("multicore", workers = n_cores)}. +Using \verb{control$future.use.plan <- future::tweaked()} will bypass +this setting. } \section{Checkpointing}{ diff --git a/man/step_tmpl_netsim_swfcalib_output.Rd b/man/step_tmpl_netsim_swfcalib_output.Rd index 4e5fe24..5a1aa50 100644 --- a/man/step_tmpl_netsim_swfcalib_output.Rd +++ b/man/step_tmpl_netsim_swfcalib_output.Rd @@ -43,9 +43,11 @@ required for the model to run. (e.g. EpiModelHIV or EpiModelCOVID)} \item{setup_lines}{(optional) a vector of bash lines to be run first. This can be used to load the required modules (like R, python, etc).} -\item{max_array_size}{maximum number of array jobs to be submitted at the -same time. Should be strictly less than the maximum number of jobs you are -allowed to submit to slurm on your HPC.} +\item{max_array_size}{maximum number of array jobs to be submitted at once. +It should be strictly less than the maximum number of jobs you are allowed +to submit to \code{slurm} on your HPC. If the number of jobs is greater than +\code{max_array_size}, they will be submitted in multiple batches. The +submission of the next batch is automatically handled by \code{slurmworkflow}.} } \value{ a template function to be used by \code{add_workflow_step}