并行大矩阵乘法

Parallel big matrix multiplication

我需要将两个大矩阵 AB 相乘,如下所示:

library(bigmemory)
library(bigalgebra)
library(biganalytics)

A <- big.matrix( replicate(100,  rnorm(10^5)) )
B <- big.matrix( replicate(10^5, rnorm(100))  )
AB <- A %*% B

我如何并行计算这个乘法?

到目前为止我遇到的唯一教程是 this one:

> library("doRedis")
> registerDoRedis(queue="example")
> L = foreach(j=1:2,.packages="VAM",.combine=c) %dopar%
+ {
+ key = paste("X",j,sep="")
+ ridx = ((j-1)*5 + 1):min((j*5),nrow(A))
+ X = A[ridx,] %*% B[,]
+ Y = as.big.matrix(X,backingfile=key)
+ vnew(Y, key)
+ key
+ }
> X = vam(matrix(L,nrow=2))
> sum(X[,] - A[,] %*% B[,])
[1] 0

但我不确定如何将其付诸实践。可能还有一种 simpler/more 有效的方法来达到相同的结果?

安装 Microsoft R Open,我从 3 秒缩短到 0.1 秒!

library(bigmemory)
library(bigalgebra)

N <- 200
M <- 1e5

A <- big.matrix(N, M, init = rnorm(N * M))
B <- big.matrix(M, N, init = rnorm(N * M))
system.time(AB <- A %*% B)