I am trying to add parallel computation option to an R (netresponse) package based on doMC and multicore. The开发者_开发百科 script works ok, but only on the second trial.
To reproduce the bug, start R and run the script below. It gets stuck on the last line. After interrupting with ctrl-c I get a few messages of "select: Interrupted system call". Then, running the same script again will give the expected result without problems.
Is some further initialization needed to get this work properly already on the first run? Or any other tips?
thanks for your support, - L
require(netresponse)
require(multicore)
require(doMC)
registerDoMC(3)
print(getDoParWorkers())
res <- foreach(i = 1:100, .combine = cbind,
.packages = "netresponse") %dopar% netresponse::vdp.mixt(matrix(rnorm(1000), 100, 10))
Heres the list of dependencies from the help page for package netresponse: "Depends: methods, igraph, graph, minet". I suspect that you are not getting all of them to the workers by just listing "netresponse" on the .packages
argument.
Quick fix for problem with foreach %dopar% is to reinstall these packages:
install.packages("doSNOW")
install.packages("doParallel")
install.packages("doMPI")
As mentioned in various threads at StackOverflow, these are responsible for parallelism in R. Bug which existed in old versions of these packages is now removed. I should mention that it will most likely help even though you are not using these packages in your project/package.
精彩评论