How to do parallel computing inside a cluster with the R future package?

Viewed 1830

I would like to distribute jobs (with a for loop) inside nodes of a cluster (several machines). I try to use the R package future to do that. I didn't know if it's the best way to do that; I tried to use foreach of the doParallel package, but I didn't succeed. How can I figure out when the number of the loop iterations is greater than the number of cluster nodes?

library(doParallel);
library(doFuture);
#library(future);

registerDoFuture();

workers <- c(rep("129.20.25.61",1), rep("129.20.25.217",1));
cl <- makeClusterPSOCK(workers, revtunnel = TRUE, outfile = "", verbose = FALSE);

plan(cluster, workers = cl)

mu <- 1.0
sigma <- 2.0

for(i in 1:3){
 res %<-%{ rnorm(i, mean = mu, sd = sigma)}
 print(i);
}
1 Answers
Related