Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

progressbar with the doMC package? #39

Closed
Spatial-R opened this issue Apr 18, 2016 · 5 comments
Closed

progressbar with the doMC package? #39

Spatial-R opened this issue Apr 18, 2016 · 5 comments

Comments

@Spatial-R
Copy link

Is the progress package also suitable for the doMC package?

@kendonB
Copy link

kendonB commented Jun 20, 2016

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

@gaborcsardi
Copy link
Member

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?

@mmahmoudian
Copy link

mmahmoudian commented Jul 13, 2018

@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.

@adayim
Copy link

adayim commented Aug 17, 2021

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.

@gaborcsardi
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants