SHARE
TWEET

Untitled

a guest Apr 20th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top