Reuse patterns in sparse matrix-matrix product with Eigen lilbrary

36 Views Asked by At

I am new to numerical computing and have some questions about pattern reusing in sparse operations.

I have two sparse matrices A and B, whose non-zero-patterns never change.

I want to compute C=A*B in this way (with C++ and Eigen3.4 sparse manipulations):

Eigen::SparseMatrix<double> A, B, C;
// init A and B
while (/* something */) {
    // update A and B, but non-zero patterns never change
    C = A * B;
    // use C
}

For A,B,C, we can assume N=10000~90000 and 5 non-zero entries in every row.

Here is my question:

The non-zero pattern of C should never change, so is there any way to exploit this property?

I don't want the actual implement be like:

  1. Allocate memory for A*B,

  2. Copy A*B to C (or redirect the pointer of C to A*B).

This is obviously not optimal. Ideally, values can be directly written to C and no memory allocation or moving is needed.

If Eigen cannot, can other BLAS libraries exploit invariant patterns?

Sorry but I cannot find related discussions in Eigen's doc. This problem could be avoided by .noalias, which is however for dense matrix. Any advice could be helpful. Thank you in advance!

0

There are 0 best solutions below