Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is a simple example of how you can create an external log file for monitoring parallel jobs in R, using doSNOW and foreach
- library(doSNOW)
- library(foreach)
- n <- 10
- cl <- makePSOCKcluster(5)
- registerDoSNOW(cl)
- writeLines(c(""), "log.txt")
- results <- foreach(i = 1:n, .combine = rbind) %dopar% {
- x <- sample(1:10, 1)
- y <- sample(seq(0.01, 0.05, by = 0.001), 1)
- res <- c(x = x,y = y)
- # Create temporary artificial delays between iterations
- Sys.sleep(0.5)
- sink("log.txt", append=TRUE)
- # Change text
- cat("Iteration", i, "\n")
- }
- stopCluster(cl)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement