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

Sparse matrix block initialization

Tags: None
(comma "," separated)
tsokar
Registered Member
Posts
7
Karma
0

Sparse matrix block initialization

Tue Jun 25, 2013 3:48 pm
Hi,
I am dealing with a sparse matrix which is composed of blocks of dense matrices (MatrixXd).

matSparse = | A 0|
|0 B |

with A and B dense matrices

In a perfect world, I would fill my matrix by assigning my dense blocks into sub-matrices of the sparse one.
Unfortunately, it is not possible :-( (cf documentation)

Do you know any mean to do it efficiently ?

Thanks !
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
It's possible in the devel branch.
tsokar
Registered Member
Posts
7
Karma
0
Great !
Thank you very much, I will give it a try !

I have also a side question : Is it possible to perform multiple matrix-matrix products with eigen in only one operation ?

C1 = A1 * B1
C2 = A2 * B2
...
Cn = An * Bn

I have seen some approaches using multidimensional arrays, but is it possible with eigen ?
I fact, my first question was related to this problem, but I fear that the performances may be very bad !

Thanks a lot !

PS : I love Eigen, the syntax is very elegant !
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
oh, then what you actually want is to form a DiagonalMatrix<MatrixXd> but, really just write a for loop, this is what will be the simplest and most efficient. Inserting your dense objects into a sparse matrix will be costly and the products will be mush slower.
tsokar
Registered Member
Posts
7
Karma
0
Just a for loop ? :o
In fact, my dense matrices are "quite" small (typically 1000x40), so I thought I could improve the efficiency of the operations by packing them together rather than looping.
In this case, perhaps openmp directives would also improve the efficiency of the for loop ?
But what I am wondering is the following : what is the most efficient between :
* sequential loop, then use eigen's multithreaded operators
* multithreaded loop and sequential eigen operators

Thanks a lot for your sound answers !
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
If, for instance, the B_i would all be the same then yes packing the matrices A_j into a single big one would improve performances. However, here there is nothing that can be done except looping over each individual products.

Using OpenMP here is a good idea and in general it is always better to parallelize at the highest level as possible, that is why in Eigen don't hurry to parallelize our own algorithms and only matrix-matrix product are parallelized.
tsokar
Registered Member
Posts
7
Karma
0
OK,
I'll give it a try.

Thank you very much !


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]