【问题标题】:Parallel with Foreach and doMC packages in Linux- Error with mclapply与 Linux 中的 Foreach 和 doMC 包并行 - mclapply 出错
【发布时间】:2014-03-24 20:51:02
【问题描述】:

我想在 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'

【问题讨论】:

    标签: linux r foreach parallels


    【解决方案1】:

    阅读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的返回对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-10
      • 2016-05-31
      • 1970-01-01
      • 2017-12-02
      相关资源
      最近更新 更多