From c803bfc9a47931d8bda25e7d3ce2ee937d81e554 Mon Sep 17 00:00:00 2001 From: Patrick Chabrier Date: Thu, 14 Sep 2023 18:04:15 +0200 Subject: [PATCH] deparallelize the wrapper if needed so --- R/stics_wrapper.R | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/R/stics_wrapper.R b/R/stics_wrapper.R index 1cd973b..b56a9d7 100644 --- a/R/stics_wrapper.R +++ b/R/stics_wrapper.R @@ -166,20 +166,23 @@ stics_wrapper <- function(model_options, # Activate the stopwatch if required if (time_display) start_time <- Sys.time() - # Managing parallel model simulations - # Managing cores number to use - cores_nb <- get_cores_nb(parallel = parallel, required_nb = cores) + if (parallel) { + # Managing parallel model simulations + # Managing cores number to use + cores_nb <- get_cores_nb(parallel = parallel, required_nb = cores) - # Launching the cluster - cl <- makeCluster(cores_nb) + # Launching the cluster + cl <- makeCluster(cores_nb) - # Stopping the cluster when exiting - on.exit(stopCluster(cl)) + # Stopping the cluster when exiting + on.exit(stopCluster(cl)) - # Registering cluster - registerDoParallel(cl) - clusterCall(cl, function(x) .libPaths(x), .libPaths()) + # Registering cluster + registerDoParallel(cl) + clusterCall(cl, function(x) .libPaths(x), .libPaths()) + `%doparornot%` <- `%dopar%` + } else `%doparornot%` <- `%do%` # Define the list of USMs to simulate and initialize results ----------------- # Check the available USMs @@ -279,7 +282,7 @@ stics_wrapper <- function(model_options, i = seq_along(sit2simulate), .export = c("run_stics", "select_results"), .packages = c("SticsRFiles") - ) %dopar% { + ) %doparornot% { ## Loops on the USMs that can be simulated ## out is a list containing vectors of: ## o list of simulated outputs,