ParLapply中的矩阵乘法或R中的foreach

时间:2017-04-01 09:23:26

标签: r matrix parallel-processing

我有一个关于使用R中的并行包进行矩阵乘法的问题。

我遇到了一种有线情况,矩阵乘法,500 * 5乘5 * 5,在群集上运行时闲置。我认为代码本身是正确的,因为它在我自己的计算机上成功运行。

我真的想不出有什么理由发生这种情况。如果有人能解释这一点,请提前致谢如果您需要更多信息,请与我们联系。

这是代码

library(doParallel)

medForest <- function(
  x.b, x.e, treat, y.b, y.e, ntree, nCore=detectCores()-1
  ) {
  cl <- makeCluster(nCore,type="FORK",outfile="debug.txt")
  registerDoParallel(cl)
  forest <- foreach(i = 1:ntree, .combine = list, .multicombine = TRUE)  %dopar%  
          {
              tree <- UniAssoc(x.b = x.b, x.e = x.e, treat = treat,
                               y.b = y.b, y.e = y.e)
              return(tree)
          }
  stopImplicitCluster()
  stopCluster(cl)
  return(forest)
}

UniAssoc <- function(x.b, x.e, treat, y.b, y.e,) {
  diff.x <- x.e[,,drop=FALSE] - x.b[,,drop=FALSE]
  diff.y <- y.e - y.b

  CCA.result <- cancor(scale(diff.x),scale(diff.y))

  # Not error but idle forever
  # diff.y is 500*5 matrix, CCA.result$ycoef is 5*5 matrix
  direction <- scale(diff.y)%*%CCA.result$ycoef

  # Will run if diff.y is reduced to a 450*5 matrix
  # No idle
  #direction <- scale(diff.y)%*%CCA.result$ycoef
  return(direction)
}

我的问题是为什么第一个矩阵乘法将永远在校园集群中空闲。这不是一种合法的行为。我正在寻找直觉上导致这种情况的原因。

0 个答案:

没有答案