The example below parallelizes 64 Sys.sleep(1)
instructions using the furrr
package.
The package progressr
is used to display the progression of the parallel execution.
This package allows to update some text details where I want to show the count of the number of terminated instructions.
But I do not know how to share a counter between the furrr
process so with my 8-core cpu it shows 8/64
at max as you can see:
library(furrr)
library(progressr)
handlers("progress")
long_process <- function(items) {
nb_of_cores <- parallel::detectCores()
plan(multisession, workers = nb_of_cores)
N <- length(items)
p <- progressr::progressor(along = items)
n <- 0
item_process <- function(item) {
n <<- n + 1
p(paste(n, "/", N))
Sys.sleep(1)
}
future_walk(items, item_process)
}
with_progress(long_process(1:64))