R with mclapply in foreach loop

Based on this post here , I tried to write the script seen here:

library(parallel)
library(doParallel)

cl<-makeCluster(2,outfile='')
registerDoParallel(cl)

foreach(i=1:5, .packages='parallel') %dopar% {
    system.time(mclapply(1:10, function(x){rnorm(1e5)},mc.cores=2))
}

stopCluster(cl)

It worked on the network, but now gives error codes:

Error in unserialize(node$con) : error reading from connection
Calls: <Anonymous> ... doTryCatch -> recvData -> recvData.SOCKnode -> unserialize
Execution halted
Error in unserialize(socklist[[n]]) : error reading from connection
Error in unserialize(node$con) : error reading from connection
Calls: <Anonymous> ... doTryCatch -> recvData -> recvData.SOCKnode -> unserialize
Execution halted

Any idea what is going on? Is it even possible to put mclapply in a foreach loop?

Edit: I also want to say that this is on a single 8-core computer, not a cluster.

+3
source share
1 answer

I was able to reproduce your problem on my Linux machine using only the "parallel" package in R 3.2.3:

library(parallel)
cl <- makeCluster(2)
clusterEvalQ(cl, library(parallel))
fun <- function(i) {
  mclapply(1:10, function(x) rnorm(1e5), mc.cores=2)
  0
}
clusterApplyLB(cl, 1:5, fun)

, , , , , "" .

, , "multicore" "parallel". multicore 0.1-8 RForge.net, :

> install.packages('multicore',,'http://www.rforge.net/')  

"multicore" "parallel" :

clusterEvalQ(cl, library(multicore))

. foreach, .packages='multicore'.

. , , "mclapply" "parallel", - , , , , .

, :

  • "mclapply" foreach "doParallel"
  • "mclapply" "multicore 0.1-8" "parallel"
  • R-Core

, R-Core, , , .

+4

Source: https://habr.com/ru/post/1623649/


All Articles