Skip to content

Commit

Permalink
deparallelize the wrapper if needed so
Browse files Browse the repository at this point in the history
  • Loading branch information
Chabrier committed Sep 14, 2023
1 parent 7eca236 commit c803bfc
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions R/stics_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c803bfc

Please sign in to comment.