我想在Linux上运行并行计算。在Windows中我设法做到这一点之后,我需要在Linux中运行下面的函数。我将包doSnow更改为doMC,这应该可以在Linux中工作,但我得到了一个与mclapply相关的错误。
代码:
foreachFunc = function(Data) {
RowFunction<-function(d)
{
(chisq.test(d)$p.value)}
P<-as.matrix(apply(Data,1,RowFunction))
return(P)}
library(doMC)
library(foreach)
number_of_cpus=4
cl<-makeCluster(number_of_cpus)
registerDoMC(cl)
Chunks<-c(1:NROW(Data_new))%%4
P<-foreach(i=0:3, .combine=rbind, mc.cores=4) %dopar% {
foreachFunc(Data_new[Chunks==i, ])}
stopCluster(cl)错误:
Error in mclapply(argsList, FUN, mc.preschedule = preschedule, mc.set.seed = set.seed, :
(list) object cannot be coerced to type 'integer'发布于 2014-02-23 18:31:45
阅读vignette("gettingstartedMC")。我可以像这样重现你的错误:
number_of_cpus=4
cl<-makeCluster(number_of_cpus)
registerDoMC(cl)
P<-foreach(i=0:3) %dopar% i
#Error in mclapply(argsList, FUN, mc.preschedule = preschedule, mc.set.seed = set.seed, :
# (list) object cannot be coerced to type 'integer'
stopCluster(cl)它的工作方式与预期一致:
registerDoMC(cores=4)
P<-foreach(i=0:3) %dopar% i说明:registerDoMC的第一个参数需要一个整数值。您为它提供了一个列表,即makeCluster的返回对象。
https://stackoverflow.com/questions/21966638
复制相似问题