Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
6881 Discussions

## Sparse matrix - vector multiplication goes wrong

Beginner
795 Views

Hi,

I encounters with some problems that have to use sparse matrix to solve, so I start to learn MKL Sparse BLAS. However, I cannot get right result when calling mkl_sparse_z_mv. I still cannot find the solution after reading the MKL reference manual and casting several demos.

So, how can I get a correct sparse matrix - vector multiplication? Any help is appreciated.

Many thanks,

Bingqi

PS: The demo is attached to this post with source code and results, along with MKL version & platform information.

4 Replies
Beginner
787 Views

Supplement: What I want to calculate is the following matrix - vector multiplication:

A = {

{ 0, 0.5i, -0.5i, 0},

{0.5i, -i, 0, -0.5i},

{-0.5i, 0, i, 0.5i},

{0, -0.5i, 0.5i, 0}

}

and

x = { 0.3799605, -0.1200395, -0.1200395, 0.6200395}

The result, Ax, should be a zero vector. But I cannot get the correct result.

I am not sure if I have missed someting in the documentation.

Employee
741 Views

Hi Bingqi!

I've found the issue in your code. You're redefining MKL_INT to be long int. This is an incorrect way of using MKL with 64-bit integers. Essentially, size of integers passed via pointers to MKL is defined by the interface layer, LP64 or ILP64 (and if you are using MKL_INT in your example code, on the definition of MKL_INT as well).

Essentially, what happened in your case is that you passed 64-bit integer arrays to mkl_sparse_z_mv routine but since you didn't do it properly, routine treated them as pointers to 32-bit integer arrays, hence incorrect result.

The correct way is:

Then you would get correct results (all zeros) for the output vector.

I hope this helps.

Best,
Kirill

Moderator
703 Views

Hi,

Can you please let us know if your issue has been resolved or not?

Regards

Rajesh

Moderator
686 Views

Hi,

We have not heard back from you, so we will close this inquiry now. If you need further assistance, please post a new question.

Regards

Rajesh.