Forked from andrie/foreach-parallel-progressbar.R
Last active
August 29, 2015 14:27
-
-
Save dreammaster38/1a0172753caddc6c8d28 to your computer and use it in GitHub Desktop.
Creating progress bars from each parallel worker using foreach and doParallel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(foreach) | |
library(iterators) | |
library(doParallel) | |
library(tcltk) | |
# Choose number of iterations | |
n <- 1000 | |
cl <- makeCluster(8) | |
registerDoParallel(cl) | |
time3 <- system.time({ | |
clusterExport(cl, c("n")) # Export max number of iteration to workers | |
k <- foreach(i = icount(n), .packages = "tcltk", .combine = c) %dopar% { | |
if(!exists("pb")) pb <- tkProgressBar("Parallel task", min=1, max=n) | |
setTkProgressBar(pb, i) | |
Sys.sleep(0.05) | |
log2(i) | |
} | |
}) | |
#Stop the cluster | |
stopCluster(cl) | |
print(time3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment