为什么plyr包不使用我的并行后端? [英] Why doesn't the plyr package use my parallel backend?
本文介绍了为什么plyr包不使用我的并行后端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在R中将parallel
包用于并行操作,而不是doSNOW
,因为它是内置的,表面上是R Project想要的方式.我做错了我无法确定的事情.例如:
I'm trying to use the parallel
package in R for parallel operations rather than doSNOW
since it's built-in and ostensibly the way the R Project wants things to go. I'm doing something wrong that I can't pin down though. Take for example this:
a <- rnorm(50)
b <- rnorm(50)
arr <- matrix(cbind(a,b),nrow=50)
aaply(arr,.margin=1,function(x){x[1]+x[2]},.parallel=F)
这很好,产生了我两列的总和.但是,如果我尝试引入并行程序包:
This works just fine, producing the sums of my two columns. But if I try to bring in the parallel package:
library(parallel)
nodes <- detectCores()
cl <- makeCluster(nodes)
setDefaultCluster(cl)
aaply(arr,.margin=1,function(x){x[1]+x[2]},.parallel=T)
它引发错误
2: In setup_parallel() : No parallel backend registered
3: executing %dopar% sequentially: no parallel backend registered
我初始化后端错误吗?
推荐答案
尝试以下设置:
library(doParallel)
library(plyr)
nodes <- detectCores()
cl <- makeCluster(nodes)
registerDoParallel(cl)
aaply(ozone, 1, mean,.parallel=TRUE)
stopCluster(cl)
由于我从未使用plyr
进行并行计算,所以我不知道为什么会发出警告.无论如何,结果是正确的.
Since I have never used plyr
for parallel computing I have no idea why this issues warnings. The result is correct anyway.
这篇关于为什么plyr包不使用我的并行后端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文