[R] Fast matrix multiplication
Ista Zahn
|@t@z@hn @end|ng |rom gm@||@com
Fri Aug 10 18:19:57 CEST 2018
Hi Ravi,
You can achieve substantial speed up by using a faster BLAS (e.g.,
OpenBLAS or MKL), especially on systems with multiple CPUs. On my (6
year old, but 8 core) system your example takes 3.9 seconds with using
the reference BLAS and only 0.9 seconds using OpenBLAS.
Best,
Ista
On Fri, Aug 10, 2018 at 11:46 AM Ravi Varadhan <ravi.varadhan using jhu.edu> wrote:
>
> Hi,
>
> I would like to compute: A %*% B %*% t(A)
>
>
>
> A is a mxn matrix and B is an nxn symmetric, positive-definite matrix, where m is large relative to n (e.g., m=50,000 and n=100).
>
>
>
> Here is a sample code.
>
>
>
> M <- 10000
>
> N <- 100
>
> A <- matrix(rnorm(M*N), M, N)
>
> B <- crossprod(matrix(rnorm(N*N), N, N)) # creating a symmetric positive-definite matrix
>
>
>
> # method 1
>
> system.time(D <- A %*% B %*% t(A))
>
>
>
> # I can obtain speedup by using a Cholesky decomposition of B
>
> # method 2
>
> system.time({
>
> C <- t(chol(B))
>
> E <- tcrossprod(A%*%C)
>
> })
>
>
>
> all.equal(D, E)
>
>
>
> I am wondering how to obtain more substantial speedup. Any suggestions would be greatly appreciated.
>
>
>
> Thanks,
>
> Ravi
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list