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

Understanding arguments of mkl_sparse_?_qr

Moghadam__Nima
Beginner
746 Views

Hello there

So I am trying to solve a sparse linear least squares min||Ax - b|| where the matrix A is sparse.

The  MKL 2019 introduced QR solver with the documentation available at

https://software.intel.com/en-us/mkl-developer-reference-c-mkl-sparse-qr

Now I cannot utilize such function and my guess is that I have not fully understood the parameters specially ldx & ldb since once I call the function nothing happens or the program crashes!

Specifically assuming

  • Matrix A is is "m x n" & specified in CSR (since only CSR is supported at the moment)
  • b is an aligned array (so 1 column only for b) and the length is m
  • The solution array x is aligned (allocated) & has a length of "n"

I call (apologies for pseudo code!)

 

success_solve = mkl_sparse_s_qr(

operation = SPARSE_OPERATION_NON_TRANSPOSE,

A = CSR description,

descr = SPARSE_MATRIX_TYPE_GENERAL,

layout = SPARSE_LAYOUT_ROW_MAJOR,

columns = 1,

x,

ldx = 1, //I have tried with both 0 & 1 and I failed at both

b,

ldb = 1 ); //again tried with both 0 & 1 and failed at both

 

Appreciate any help && cheers

0 Kudos
1 Solution
Kirill_V_Intel
Employee
746 Views

Hello,

First of all, I believe we have an example for Sparse QR functionality (look in examples/spblasc). In the example sparse_d_qr.c you can find an example of the usage. As it follows from there, when solving Ax = b with x and b being vectors, the call looks like this:

mkl_sparse_d_qr( SPARSE_OPERATION_NON_TRANSPOSE, csrA, descrA, SPARSE_LAYOUT_COLUMN_MAJOR, 1, x, ncols, b, nrows )

Hence, you need to set ldx = number of columns in the matrix, and ldb = number of rows in the matrix.

I hope this helps!

Best,
Kirill

 

View solution in original post

0 Kudos
3 Replies
mecej4
Honored Contributor III
746 Views

I find the documentation confusing, but I am able to view the MKL-Fortran documentation for the same routine (mkl_sparse_d_qr) and infer what the arguments are supposed to be.

The arguments ldA and ldX should be assigned proper values when the solver is being called with X and B containing more than one column. Those matrices are held in dense storage format, and the declared sizes may be larger than needed for the specific matrices in the call (because, at least in Fortran 77, you could not allocate matrices dynamically). In your case, however, X and B have only one column, so the values passed for ldA and ldX will never be used, but the arguments are needed as place-holders.

MKL comes with an example, "sparse_d_qr.c" (unzip the C examples Zip file to obtain it). 

If your program is crashing or, as you wrote, "nothing happens" (I don't know what you expected to happen), the problem lies elsewhere. Please post the complete source code (zip and attach the zip to your reply), and describe how you compiled and linked the program.

0 Kudos
Kirill_V_Intel
Employee
747 Views

Hello,

First of all, I believe we have an example for Sparse QR functionality (look in examples/spblasc). In the example sparse_d_qr.c you can find an example of the usage. As it follows from there, when solving Ax = b with x and b being vectors, the call looks like this:

mkl_sparse_d_qr( SPARSE_OPERATION_NON_TRANSPOSE, csrA, descrA, SPARSE_LAYOUT_COLUMN_MAJOR, 1, x, ncols, b, nrows )

Hence, you need to set ldx = number of columns in the matrix, and ldb = number of rows in the matrix.

I hope this helps!

Best,
Kirill

 

0 Kudos
Moghadam__Nima
Beginner
746 Views

First of all thanks so much for quick response.

 

1) I did not see the message of Kirill, so I prepared a file for mecej4 (please see the attachment).

2) However, I confirm the correction of Kirill works absolutely correctly (again please see the attached test).

 

Thanks again & cheerz

0 Kudos
Reply