Creating progress bars with foreach parallel processing

March 10, 2015
By

(This article was first published on Revolutions, and kindly contributed to R-bloggers)

by Andrie de Vries

In my previous post, I demonstrated how to get some status of running jobs on a parallel back end. However, I stopped short of actually demonstrating progress bars. In this post I demonstrate how to do this.

The StackOverflow question How do you create a progress bar when using the “foreach()” function in R? () asks the question how to create progress bars with foreach.

This question attracted some helpful answers, but ultimately didn’t answer the question.  In particular, Steve Weston said this approach is flawed, since

It won't work well with doParallel because doParallel only calls the combine function after all of the results have been returned, since it is implemented by calling the parallel clusterApplyLB function. This technique only with works well with backends that call the combine function on-the-fly, like doRedis, doMPI, doNWS, and (defunct?) doSMP.

My experiments

However, this set me thinking.  Could it be that one could trigger a tcltk progress bar in each worker?

Thus I started to experiment, and came up with the following code.  On my windows machine, using doParallel, this seems to work reliably (but I could not get this approach to work on Linux using doMC).

When you run this code, you should see synchronous progress bars, one for each worker:

Multi-taskbar

Conclusion

Although it takes some work, and there isn’t a single solution for all cases, it is possible to get progress bars for at least some parallel back ends.

In this post I demonstrated how to create progress bars using doParallel on Windows, but failed to replicate on Linux.

Can you do better?

To leave a comment for the author, please follow the link and comment on their blog: Revolutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)