Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Nicolas_B_3
Beginner
124 Views

Sparse BLAS - sparse_dense matrix multiplication with zero indexing and colmajor matrix

Hello,

I  would like to use MKL sparse blas in C++ for computing multithreaded sparse-dense matrix multiplication.
I would like to compute C = S * B, with S a sparse matrix in format coo or csc in 0-indexing and
C and B two dense matrix in ColMajor and 0-indexing format.
In all the mkl_?coomm or mkl_?cscmm functions it seems like we can only compute 
this product with matrix in 0-indexing and Row major format...
Is there an effcient (fast)  way to compute this product with Colmajor and 0-indexing format for dense matrix,
which means not using not using transposition for dense matrix.


 

 

0 Kudos
6 Replies
asd__asdqwe
Beginner
124 Views

Hi,

No it is not possible, unless you use the inspector-executor routines instead https://software.intel.com/en-us/articles/intel-math-kernel-library-inspector-executor-sparse-blas-routines.

mecej4
Black Belt
124 Views

It may help if you (Nicolas) describe how you intend to use the result matrix C. With sparse matrices, operations are often more efficient when one does not attempt to store an intermediate matrix in the usual dense matrix form (two-dimensional array).

Nicolas_B_3
Beginner
124 Views

Ok thanks for your help,

qweasd q, it seems that the inspector-executor routines are not available on my MKL version...

I want to use MKL for interoperability with C++ Eigen library but what I see, if I use    mkl_sparse_?_mm function for sparse matrix - dense matrix product, I have to use built-in type "sparse_matrix_t" for sparse matrix, I see you can construct a "sparse_matrix_t" from COO or CSC  pointer but my question is : does it take a lot of time to build this "sparse_matrix_t" from COO or CSC pointer from a large sparse matrix ?

Does it duplicate the memory or just link the sparse_matrix_t directly to the pointer ?

Nicolas_B_3
Beginner
124 Views

to respond to mecej4,

I have a list of sparse matrix {S1,S2,...,Sn} and A a dense matrix and I want to compute C = Sn*Sn-1*...*S2*S1*A

the pseudo-code I use for that is :

for i=1 to n  do C = Si*A;A=C; end for

 

mecej4
Black Belt
124 Views

If matrices S1, S2, ..., all have the same sparseness pattern, or if you know in advance the sparseness pattern in the final product, some efficiency gains may be possible by doing suitable programming.

This routine for converting from COO to CSR/CSC may be useful: http://www.cs.umn.edu/~agupta/example/triplet2cs.c .

Another library worth considering for your purposes: http://people.uniroma2.it/salvatore.filippone/psblas/ .

Ying_H_Intel
Employee
124 Views

Hi Nicolas

As qweasd and mecej4 mentioned, there is some special optimization with such sparse matrix multiply loop.  If you'd like to use MKL, You  can use MKL 11.3 which have the  functionality of the inspector-executor API for Sparse BLAS (SpMV 2)..  and it also provides the optimization with the matrix sparsity pattern detect and reused. 

mkl_sparse_optimize

Analyzes matrix structure and performs optimizations using the hints provided in the handle. Generally, specifying a higher number of expected operations allows for more aggressive and time consuming optimizations. Syntax Fortran: stat = mkl_sparse_optimize ( A ) C: sparse_status_t mkl_sparse_optimize( sparse_matrix_t A );

there is test example code in MKL install directory/ example folder.   You can try them. 

Best Regards

Ying 

 

 

Reply