Showing results for

- Intel Community
- Software Development SDKs and Libraries
- Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
- operate on diagonal of a sparse matrix in csr format

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted
hi,
I want to efficiently operate only on the diagonal of a large non-singular sparse_status_t matrix (in csr format).
More precisely, if 'A' is my matrix then I want to do:
A - alpha*I
where 'alpha' is a positive scalar and 'I' is the Identity.
I could create the matrix alpha*I and do a sparse matrix - sparse matrix - multiplication, but that would take too much space and time. Is there a better way to do this?
best regards, Franz

Robert_E_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-27-2018
11:35 AM

25 Views

Robert E.

Accepted Solutions

Highlighted

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-27-2018
02:38 PM

25 Views

First of all, the CSR representation of A is a compact representation, and may have only a few or no diagonal elements at all. Therefore, if you wish to modify the diagonal, you must already have a full diagonal, possibly many or all elements of which are filled with zero values.

If you wish to do the diagonal update repeatedly, it would be efficient to pre-compute and store a separate array, say, ID(1:N), containing the column indices of the diagonal elements -- the subset of JA corresponding to the diagonal.

4 Replies

Highlighted

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-27-2018
02:38 PM

26 Views

First of all, the CSR representation of A is a compact representation, and may have only a few or no diagonal elements at all. Therefore, if you wish to modify the diagonal, you must already have a full diagonal, possibly many or all elements of which are filled with zero values.

If you wish to do the diagonal update repeatedly, it would be efficient to pre-compute and store a separate array, say, ID(1:N), containing the column indices of the diagonal elements -- the subset of JA corresponding to the diagonal.

Highlighted
another question: I observed some strange behavior from the sparse_matrix_t handle.
here is what I did:
I exported the pointers to the internal structure via mkl_sparse_?_export_csr and changed some values.
To check if the changes were successful I exported the internal data again. The values seem to have changed.
But when I call mkl_sparse_?_mv afterwards the old values are used.
I have to create a new handle right before the call to mkl_sparse_?_mv so that the new values are used.
I couldn't find any detailed information on sparse_matrix_t handles, I've searched the C-reference manual and the user guide. I can also provide some code if necessary.

Robert_E_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-01-2018
04:57 PM

25 Views

Robert E.

Highlighted

MariaZh

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-01-2018
05:27 PM

25 Views

Hi Franz,

It is an expected behavior in your case.

IE SpBLAS perform a lot of different optimizations on a user's data. However, the data itself will not be changed during calls (one exception here is mkl_sparse_order routine).

mkl_sparse_?_export_csr allows one to export the initial pointers or to get CSR representation of resulting matrix (e.g. after mkl_sparse_spmm).

If you need to change several values in the handle you can use mkl_sparse_?_set_value routine. Please, refer to https://software.intel.com/en-us/mkl-developer-reference-c-mkl-sparse-set-value

Hope, this will help!

Best regards,

Maria

Highlighted
Hi Maria,
Thanks for the advice. I tried the set_value routine but that didn't change anything. The problem was that my tiny 9x9 test-matrix had too many non-zero entries (only 2-3 zeros). So I guess the mkl library is expecting the matrix to be sparse independent of its size. Using a sparser matrix resolved the issue even without incorporating the set_value routine.
Kind regards,
Franz

Robert_E_

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-02-2018
01:11 AM

25 Views

Robert E.

For more complete information about compiler optimizations, see our Optimization Notice.