Skip to content

Commit

Permalink
proper set up of {future} #156
Browse files Browse the repository at this point in the history
o changed `maxSize` option so that it will unload `on.exit`

o changed `plan` option so that it will unload `on.exit`

o removed the force close of parallel processing to sequential because of the addition of `on.exit` with `plan`
  • Loading branch information
AlexChristensen committed Mar 1, 2024
1 parent 4475d80 commit eb8210a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ restore_state <- function()

#' @noRd
# Wrapper for parallelization ----
# Updated 24.10.2023
# Updated 01.03.2024
parallel_process <- function(
iterations, # number of iterations
datalist = NULL, # list of data
Expand Down Expand Up @@ -591,16 +591,22 @@ parallel_process <- function(
}

# Set max size
options(future.globals.maxSize = memory_available)
memory_options <- options(future.globals.maxSize = memory_available)

# Set up undo changes
on.exit(memory_options)

}

# Set up plan
future::plan(
parallel_plan <- future::plan(
strategy = "multisession",
workers = ncores
)

# Set up undo changes
on.exit(future::plan(parallel_plan))

# Check for progress
if(isTRUE(progress)){

Expand Down Expand Up @@ -682,9 +688,6 @@ parallel_process <- function(

}

# Force close of connections
future::plan(strategy = "sequential")

# Return results
return(results)

Expand Down

0 comments on commit eb8210a

Please sign in to comment.