Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Output of parallel computing in R on Windows

$
0
0

I would like to do some parallel computing in R on Windows.

library(doSNOW)
library(foreach)
cl<-makeCluster(4)
registerDoSNOW(cl)

nn = seq(2,20, by=2)
nn2 = rep(-1,10)
vector.accessed.within.iteration = rep(0, 10)

y = foreach(i=1:10) %dopar% {

   print(paste0('i = ', i))
   nn2[i] = (nn[i])^2
   vector.accessed.within.iteration[i] = nn[i] + nn2[i]
   nn2[i]
} 

stopCluster(cl)

When running the code, y is returned as the list of squares from 2 to 20, as intended. However, neither vector nn2 nor vector.accessed.within.iteration are modified within foreach loop. Furthermore, the printing print(paste0('i = ', i)) does not occur.

Is it possible to run iterations of a loop in parallel on windows while also displaying messages and modifying variables from global environment?


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>