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

## Problem using MKL_SCOOSV to solve a sparse matrix

Beginner
443 Views
Hello everyone,

I am trying to use Sparse BLAS to solve a least-square system (more equations than unknown). I am using Coordinate format for my sparse matrix and use mkl_scoosv as my solver function.

When I try to run, I receive an error: MKL ERROR: Parameter 4 was incorrect on entry to MKL_SCOOSV

I have tried different combination of matdescra but the error is still there and there is no result written to my solution vector. Am I missing something really fundamental here?

I am attaching the small piece of code below. Thank you for your time.
```[cpp]	// we try to solve small sparse matrix in least square sense
/* Our matrix is
* 1 2 3 4   1
* 0 1 2 0   2
* 0 1 2 5   0
* 4 -1 0 2  5
* 0 0 0 3   6
* 1 2 0 0   8
* */
// result should be: [1.599 2.909 -2.373 0.611]

int nRows = 6;
int nNonZeros = 15;
int nCols = 4;
int nRhs = 1;

// zero-based indexing (C-style)
int rowIdx[15] = {0, 0, 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 5, 5};
int colIdx[15] = {0, 1, 2, 3, 1, 2, 1, 2, 3, 0, 1, 3, 3, 0, 1};
float values[15] = {1, 2, 3, 4, 1, 2, 1, 2, 5, 4, -1, 2, 3, 1 ,2};
float rhs[6] = {1, 2, 0, 5, 6, 8};
float sol[4];

// call sparse matrix solver
float alpha = 1;
char transpose = 'n';
char matdescra[6] = "G  C";
mkl_scoosv(&transpose, &nRows, , matdescra, values, rowIdx, colIdx, &nNonZeros, rhs, sol);

printf("Solution is [%f %f %f %f %f]n", sol[0], sol[1], sol[2], sol[3], sol[4]);[/cpp]```

8 Replies
New Contributor I
443 Views

According to the Intel MKL Reference Manual, sparse matrix can be general and represent the whole square matrix but for NIST like triangular routines, matdescra(1) must be T' or D' as it is described in the table 2.7 entitled "Possible combinations of element values of the parameter matdescra" (see page 216).

Best Regards
Victor

Beginner
443 Views

According to the Intel MKL Reference Manual, sparse matrix can be general and represent the whole square matrix but for NIST like triangular routines, matdescra(1) must be T' or D' as it is described in the table 2.7 entitled "Possible combinations of element values of the parameter matdescra" (see page 216).

Best Regards
Victor

Hi Victor,

Thanks for the quick response. I found out the problem yesterday night as well and have not been able to reply to this thread. I guess I will have to wait for MKL to include a routine for matrix multiplication between two sparse matrices. That way I can solve my rectangular sparse matrix using DSS.
Employee
443 Views

MKL Sparse BLAS 10.1 provides routines for matrix multiplication and addition between two sparse matrices. The routines are provided for all types of precisions. However these routines are only for the compressed sparse row format.

All the best
Sergey
Beginner
443 Views

MKL Sparse BLAS 10.1 provides routines for matrix multiplication and addition between two sparse matrices. The routines are provided for all types of precisions. However these routines are only for the compressed sparse row format.

All the best
Sergey
Hi Sergey,

Thanks for the information. I have gone through the documentation of Sparse BLAS one more time in search for the routine that you mentioned but still without any luck. Would you mind give me the routine name?

Also, on another note, this page of Sparse BLAS suggest that there is no multiplication routine available for sparse matrices.

Moderator
443 Views
mkl_?csrmultcsr
where ? means s (real), d (double), c (single complex), z (double comlex)
Computes product of two sparse matrices stored in the CSR format (3-array variation) with one-based indexing.

Beginner
443 Views
mkl_?csrmultcsr
where ? means s (real), d (double), c (single complex), z (double comlex)
Computes product of two sparse matrices stored in the CSR format (3-array variation) with one-based indexing.

Thank you, Gennady. Now I can do transpose(A) * A then run DSS to solve my matrix.
Beginner
443 Views

Hello all,

I don't understand how Dat Chu could solve the problem. The description of matdescra for mkl_scoosv is cryptic to me.

His matrix (as mine today) is neither diagonal (D) nor triangular (T): in my view it is general (G), but this does not work.

Question: Given the matrix of Dat Chu from 3/3/2009, what is the complete correct string in matdescra (fortran) for mkl_scoosv?

Best regards,

Johannes

Black Belt
443 Views

Johannes: This is an old thread that you brought back to life. The code that Dat Chu posted was not adequate for the stated purpose. His final comment, "Now I can do transpose(A) * A then run DSS to solve my matrix" makes me suspect that he was forming the normal equations for solving the least squares problem (along the lines described in https://software.intel.com/en-us/forums/intel-math-kernel-library/topic/298477 ); if so, that was not a good way of obtaining a least-squares solution.

The routines mkl_?coosv are for solving A.x = α.y, where A is a square matrix in COO storage format, x and y are vectors, and α is a scalar.

When A is not square,  and has more rows than columns, these routines can only be used after A has been decomposed (using a factorization such as Q-R) and both sides of the overdetermined equation set A.x = b have been pre-multiplied by QT, leaving a triangular system to be solved.

Furthermore, as of now (2018) mkl_?coosv is marked "deprecated".

Perhaps it would be more useful if you started a new thread in which you described the nature of the problem that you wish to solve now.