我有一个问题得到一些代码与R中的并行包一起使用。我使用R 2.15。R并行S4类集群错误
这里有一个简单的例子...我有一个文件 'animal.R',这包含以下内容:
# animal.R
setClass("Animal", representation(species = "character", legs = "numeric"))
##Define some Animal methods
setGeneric("count",function(x) standardGeneric("count"))
setMethod("count", "Animal", function(x) { [email protected]})
setGeneric("countAfterChopping",function(x) standardGeneric("countAfterChopping"))
setMethod("countAfterChopping", "Animal", function(x) { [email protected] <- [email protected]; [email protected]})
然后,在我的R端子,我跑:
library(parallel)
source('animal.R')
开始两个节点的本地集群:
cl <- makeCluster(rep('localhost', 2))
讲述动物类的群集节点:
clusterEvalQ(cl, parse('animal.R'))
然后在集群上运行一些代码:
# This works
parSapply(cl, list(daisy, fred), count)
# This doesn't...
parSapply(cl, list(daisy, fred), countAfterChopping)
停止集群:
stopCluster(cl)
工程按预期parSapply第一个呼叫,但第二个产生这个错误:
Error in checkForRemoteErrors(val) :
2 nodes produced errors; first error: "Animal" is not a defined class
任何想法发生了什么?为什么第二次调用parSapply不起作用?
当你'parse' animal.R,你会得到一个未计算的表达,所以你既可以使用'clusterEvalQ(CL,EVAL(解析('animal.R ')))'或者只是来源脚本。这是否有诀窍? – BenBarnes
啊,是的......这似乎在伎俩。非常感谢! – Ash