This book is in Open Review. I want your feedback to make the book better for you and other readers. To add your annotation, select some text and then click the on the pop-up menu. To see the annotations of others, click the in the upper right hand corner of the page

Cours 2 Paralléliser

library(foreach)

cores = 2 # nbr of cores to use
# parallel::detectCores() # 8
i <- NULL
j = length(object)

# L'enregistrement des clusters
cl <- parallel::makeCluster(cores)
doSNOW::registerDoSNOW(cl)

# Progress bar:
pb <- txtProgressBar(min = 0, max = j, style = 3)
progress <- function(n) setTxtProgressBar(pb, n)
opts <- list(progress = progress)

output <- foreach::foreach(
  i=1:j,
  .packages = c("magrittr"), # necessary packages
  .options.snow = opts # ProgressBar
) %dopar% {
  print(i) # to check
  # the function to parallelise:
  las_to_dem(lases[i], 
             las_path = las_path,
             mnt_path = mnt_path)
}

# close progressbar and cluster
close(pb)
stopCluster(cl)