Marius Hofert
2010-Dec-28 09:57 UTC
[R] foreach + dopar: how to check progress of parallel computations?
Dear expeRts,
I use foreach to do parallel computations. Is it possible to have some progress
output written while the computations are done? In the minimal example below, I
just print a number ("n") to check the progress. If you run this
example with "%do%" instead of "%dopar%", then the
computations are done sequentially and the number n is printed to the console. I
am looking for something similar but with %dopar%. In the minimal example you
can see that n is not written to the console if the computations are done in
parallel. How [with which construction] can I check the progress?
Cheers,
Marius
## load packages
library(doSNOW)
library(Rmpi)
library(foreach)
## parameters
param.1 <- 1:2 #c("a1", "b1")
param.2 <- 1:4 #c("a2", "b2", "c2",
"d2")
## setup cluster
cl <- makeCluster(mpi.universe.size(), type ="MPI")
registerDoSNOW(cl)
## main work
n <- 1
res <- foreach(p1 = param.1) %:% foreach(p2 = param.2) %dopar% {
print(n)
p1 * p2
n <- n + 1
}
stopCluster(cl) # stop cluster
res # result