开发者

foreach within package function: does not work on first call

开发者 https://www.devze.com 2023-03-20 11:12 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消