[R] mclapply in foreach

Abdel Halloway abdel.halloway at gmail.com
Thu Feb 18 21:33:29 CET 2016


Can a person put mclapply in a foreach loop? Based on this post here
<http://stackoverflow.com/questions/34704733/parallel-r-with-foreach-and-mclapply-at-the-same-time>,
I wrote a 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 initially but is now throwing up 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's going on? This is on a single machine, not a cluster.

	[[alternative HTML version deleted]]



More information about the R-help mailing list