Parallel for loop R
parallel-foreach, r
Solution
library(doSNOW)
sample_fun <- function(x,y) {
# do something with x,y and return value
}
threads <- 8
N <- 10000
cl <- makeCluster(threads)
registerDoSNOW(cl)
result <- foreach(i=1:N) %dopar% sample_fun(i,i+1)
stopCluster(cl)
http://www.joyofdata.de/blog/parallel-computing-r-windows-using-dosnow-foreach/
Problem
I am calling a function inside a for loop. ``` sample_fun <- function(x,y) { # do something with x,y and return value } My loop looks like result = list() for(i in 1:10000) result[i] = sample_fun(i,i+1) ``` How do i parallelize this loop. Using foreach and dopar gives me subscript error.