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

Sparse matrix - vector multiplication goes wrong

BQ_Li
Beginner
1,050 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.

0 Kudos
4 Replies
BQ_Li
Beginner
1,042 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.

0 Kudos
Kirill_V_Intel
Employee
996 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:

Change your compilation and link line according to MKL link line advisor for 64-bit integers (i.e. choose ("C API with 64-bit integers" option). You would need to add -DMKL_ILP64 to your compilation line and also link against mkl_intel_ilp64 instead of mkl_intel_lp64 interface library.

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

I hope this helps.

Best,
Kirill

0 Kudos
MRajesh_intel
Moderator
958 Views

Hi,


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


Regards

Rajesh


0 Kudos
MRajesh_intel
Moderator
941 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.


0 Kudos
Reply