Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. # This is a simple example of how you can create an external log file for monitoring parallel jobs in R, using doSNOW and foreach
  2.  
  3. library(doSNOW)
  4. library(foreach)
  5.  
  6. n <- 10
  7.  
  8. cl <- makePSOCKcluster(5)
  9. registerDoSNOW(cl)
  10. writeLines(c(""), "log.txt")
  11.  
  12. results <- foreach(i = 1:n, .combine = rbind) %dopar% {
  13.  
  14. x <- sample(1:10, 1)
  15. y <- sample(seq(0.01, 0.05, by = 0.001), 1)
  16. res <- c(x = x,y = y)
  17.  
  18. # Create temporary artificial delays between iterations
  19. Sys.sleep(0.5)
  20.  
  21. sink("log.txt", append=TRUE)
  22. # Change text
  23. cat("Iteration", i, "\n")
  24. }
  25.  
  26. stopCluster(cl)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement