[英]Matrix operations in R: parallelization, sparse operations, GPU computation
The basic aim of my question is how to achieve the best performance of matrix operations in R
using Matrix
package. 我的问题的基本目标是如何使用
Matrix
包在R
实现矩阵运算的最佳性能。 In particular I want to parallelize operations (multiplication) and work with sparse matrices using computation on CUDA GPU. 特别是我希望并行化操作(乘法)并使用CUDA GPU上的计算来处理稀疏矩阵。
Details 细节
According to the documentation of the Matrix
package in R cran
根据
R cran
Matrix
包的文档
A rich hierarchy of matrix classes, including triangular, symmetric, and diagonal matrices, both dense and sparse and with pattern, logical and numeric entries.
丰富的矩阵类层次结构,包括三角形,对称矩阵和对角矩阵,包括密集和稀疏矩阵,以及模式,逻辑和数字条目。 Numerous methods for and operations on these matrices, using 'LAPACK' and 'SuiteSparse' libraries.
使用'LAPACK'和'SuiteSparse'库对这些矩阵进行了大量的操作和操作。
It seems that thanks to the SuiteSparse
I should be able to perform basic operations on sparse matrices using the GPU (CUDA). 看来,由于
SuiteSparse
我应该能够使用GPU(CUDA)对稀疏矩阵执行基本操作。 In particular the documentation of the SuiteSparse lists the following: 特别是SuiteSparse的文档列出了以下内容:
SSMULT and SFMULT: sparse matrix multiplication.
SSMULT和SFMULT:稀疏矩阵乘法。
On my Gentoo I have installed suitesparse-4.2.1
along with suitesparseconfig-4.2.1-r1
. 在我的Gentoo上,我安装了
suitesparse-4.2.1
以及suitesparseconfig-4.2.1-r1
。 Also I have lapack
, scalapack
and blas
. 我也有
lapack
, scalapack
和blas
。 The R sessionInfo()
looks as follows: R
sessionInfo()
如下所示:
R version 3.4.1 (2017-06-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Gentoo/Linux
Matrix products: default
BLAS: /usr/lib64/blas/reference/libblas.so.0.0.0
LAPACK: /usr/lib64/lapack/reference/liblapack.so.0.0.0
locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Matrix_1.2-10
loaded via a namespace (and not attached):
[1] compiler_3.4.1 grid_3.4.1 lattice_0.20-35
I have also set the environmental variable: 我还设置了环境变量:
export CHOLMOD_USE_GPU=1
which I found on one forum and potentially should allow GPU usage. 这是我在一个论坛上发现的,可能应该允许GPU使用。
Basically, everything looks as ready to go, however, when I run a simple test: 基本上,当我运行一个简单的测试时,一切看起来都准备好了:
library(Matrix)
M1<-rsparsematrix(10000,10000,0.01)
M<-M1%*%t(M1)
It seems that GPU are not working, as if R
ignores the suitesparse
features. 似乎GPU没有工作,好像
R
忽略了suitesparse
功能。
I know the questions are quite broad, but: 我知道问题很广泛,但是:
R
should be compiled in a specific, strict way to work with suitesparse
? R
来使用suitesparse
? Matrix
package uses all shared libraries for parallelization and sparse operations (with GPU usage)? Matrix
包使用所有共享库进行并行化和稀疏操作(使用GPU)? Matrix
package? Matrix
包在CUDA / GPU计算上运行矩阵运算吗? As far as I looked through the Stack and other forums, this question shouldn't be a duplicate. 据我浏览Stack和其他论坛,这个问题不应该是重复的。
Matrix
package contains subset of SuiteSparse
and this subset is built-in into package. Matrix
包包含SuiteSparse
子集 ,该子集内置于包中。 So Matrix
doesn't use your system SuiteSparse
(you can easily browse Matrix
source code here ). Matrix
不使用您的系统SuiteSparse
(您可以在此处轻松浏览Matrix
源代码)。 sparse_matrix * sparse_matrix
multiplications are hard to efficiently parallelize - strategies vary a lot depending on the structure of both matrices. sparse_matrix * sparse_matrix
乘法很难有效地并行化 - 策略根据两个矩阵的结构而变化很大。 mclapply
. mclapply
。 I doubt this will help. Eigen
and RcppEigen
and perform SSMULT there. Eigen
和RcppEigen
并在那里执行SSMULT。 I believe it could be quite faster (but still single threaded).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.