progress icon indicating copy to clipboard operation
progress copied to clipboard

progressbar with the doMC package?

Open Spatial-R opened this issue 8 years ago • 4 comments

Is the progress package also suitable for the doMC package?

Spatial-R avatar Apr 18 '16 13:04 Spatial-R

Or the parallel package? If not, +1 for this feature.

kendonB avatar Jun 20 '16 02:06 kendonB

I am not sure what it would take to implement this, to be honest. E.g. for parallel, one would need parallel to communicate back, how much of the work has been done already. Is that even possible?

gaborcsardi avatar Apr 22 '18 20:04 gaborcsardi

@gaborcsardi I did some searching and the following is what I've found:

library("foreach")
library("doParallel")
library("progress")

registerDoParallel(parallel::makeCluster(7, outfile = ""))
    
pb <- progress_bar$new(
            format = " [:bar] :percent in :elapsed",
            total = 30, clear = FALSE, width = 80, force = T)
a <- foreach (i  = 1:30) %dopar% {
    pb$tick()
    Sys.sleep(0.5)
}


pb <- txtProgressBar(title = "Iterative training", min = 0, max = 30, style = 3)

foreach (i  = 1:30) %dopar% {
    setTxtProgressBar(pb, i)
    Sys.sleep(0.5)
}

stopCluster(cl)

The txtProgressBar only works when the stype is 2 or 3. According to the function's manual:

style = 1 and style = 2 just shows a line of char. They differ in that style = 2 redraws the line each time, which is useful if other code might be writing to the R console. style = 3 marks the end of the range by | and gives a percentage to the right of the bar.

I think the reason txtProgressBar works is because the outfile = "" exists while making the cluster.

I think mimicking what txtProgressBar does for style 2 would solve this.

mmahmoudian avatar Jul 13 '18 10:07 mmahmoudian

I don't know if there is any update on this, what about pbapply package? But I find this package do more regarding the progress bar.

adayim avatar Aug 17 '21 21:08 adayim

In general this is not possible currently, I believe. You might get lucky if the parallel processes use the same terminal as the main process, but in general we would need support from parallel to implement this.

gaborcsardi avatar Nov 01 '23 14:11 gaborcsardi