Understanding arguments of mkl_sparse_?_qr

Understanding arguments of mkl_sparse_?_qr

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


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(


A = CSR description,



columns = 1,


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


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


Appreciate any help && cheers

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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.

Best Reply


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!



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


Leave a Comment

Please sign in to add a comment. Not a member? Join today