This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Memory Optimization for Sparse-Dense Multiplication

Tags: None
(comma "," separated)
flaviotruzzi
Registered Member
Posts
7
Karma
0
Hi everyone!

I'm working with sparse matrices (644k x 644k) and making a product with a column (644k).
Code: Select all
S = 644204;
mat = SparseMatrix<float>(S,S);
col =VectorXf(S);

col = mat*col;


Such operation, is working well and very fast for S=400k, but with a bigger value of S, the kernel is killing the process when it reaches about 60% of my RAM, I tryed to change that last operation to:

Code: Select all
for (int s = 0; s < S; s++) {
  col(s) = mat.row(s)*col(s);
}


Trying to reduce the memory consumption, but It arose an error saying that my matrices must be row major, but when I change it to row major using:

Code: Select all
SparseMatrix<float,RowMajor>


I get the following error:

g++ -I/usr/include/eigen3/ -I/usr/include/ -O3 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"MDP.d" -MT"MDP.d" -o "MDP.o" "../MDP.cpp" -std=c++0x -pg -msse4
../MDP.cpp: In member function 'void MDP::ValueIteration()':
../MDP.cpp:163:29: error: cannot convert 'const Type {aka const Eigen::SparseTimeDenseProduct<Eigen::SparseInnerVectorSet<Eigen::SparseMatrix<float, 1>, 1>, Eigen::Matrix<float, -1, 1> >}' to 'Eigen::DenseCoeffsBase<Eigen::Matrix<float, -1, -1>, 1>::Scalar {aka float}' in assignment


Any Ideas will be great! Thanks
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
In Eigfen, Sparse*Dense products do not make use of any additional memory, except one temporary to avoid aliasing issue when doing: col = mat*col; (col is used both on the right and left hand-side). For a row-major matrix it is equivalent to:

VectorXf tmp(s);
for (int s = 0; s < S; s++) {
tmp(s) = mat.row(s).dot(col(s));
}
col = tmp;

Again note that the temporary here is needed.

How many non-zeros does mat contain?
flaviotruzzi
Registered Member
Posts
7
Karma
0
Normally not least than 4.333.736 .


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]