Skip to content

Commit

Permalink
Merge pull request #9 from Chabrier/deparallelize
Browse files Browse the repository at this point in the history
deparallelize the wrapper if needed so
  • Loading branch information
sbuis authored Feb 16, 2024
2 parents ccb00a6 + c803bfc commit 3b0265a
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 3b0265a

Please sign in to comment.