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

Using LAPACK to invert sparse matrices

thomasdd
Beginner
1,856 Views
I've some small square matrices (so around 100x100) that are sparse. I want to use the LAPACK functions to compute the inverse. To do this, I've tried to use the function dgetrf (in C++). But always the info return value is > 0. I've checked the matrix, but it has no zero values on the diagonals. Because the matrix is square, I can use n=m=lda for the input parameters. Is it right? Is there any trouble known when using sparse matrices with LAPACK? I've also check the matrices in Matlab, they are non-singular.

Thanks for any hints,

Thomas
0 Kudos
1 Solution
Gennady_F_Intel
Moderator
1,856 Views
Quoting - thomasdd
Quoting - Melvin
Can you post some example code so that I can see what you are doing?
A very simple example:

int n = 4, m = 4, lda = 4;
int ipiv = 0, info = 0;
double matrix[16] = {1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1};
dgetrf(&m, &n, matrix, &lda, &ipiv, &info);
std::cout << "INFO = " << info << std::endl;

In this case, info is 4! Is there anything wrong in the call of dgetrf?

Thomas

Thomas,
ipiv is the array, but not integer
the dimention at least max(1,min(m,n)), therefore for your case ipiv[4].
Please refer to the mkl's reference manual.
--Gennady

View solution in original post

0 Kudos
4 Replies
Melvin_Robinson
New Contributor I
1,856 Views
Quoting - thomasdd
I've some small square matrices (so around 100x100) that are sparse. I want to use the LAPACK functions to compute the inverse. To do this, I've tried to use the function dgetrf (in C++). But always the info return value is > 0. I've checked the matrix, but it has no zero values on the diagonals. Because the matrix is square, I can use n=m=lda for the input parameters. Is it right? Is there any trouble known when using sparse matrices with LAPACK? I've also check the matrices in Matlab, they are non-singular.

Thanks for any hints,

Thomas
Can you post some example code so that I can see what you are doing?
0 Kudos
thomasdd
Beginner
1,856 Views
Quoting - Melvin
Can you post some example code so that I can see what you are doing?
A very simple example:

int n = 4, m = 4, lda = 4;
int ipiv = 0, info = 0;
double matrix[16] = {1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1};
dgetrf(&m, &n, matrix, &lda, &ipiv, &info);
std::cout << "INFO = " << info << std::endl;

In this case, info is 4! Is there anything wrong in the call of dgetrf?

Thomas
0 Kudos
Gennady_F_Intel
Moderator
1,857 Views
Quoting - thomasdd
Quoting - Melvin
Can you post some example code so that I can see what you are doing?
A very simple example:

int n = 4, m = 4, lda = 4;
int ipiv = 0, info = 0;
double matrix[16] = {1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1};
dgetrf(&m, &n, matrix, &lda, &ipiv, &info);
std::cout << "INFO = " << info << std::endl;

In this case, info is 4! Is there anything wrong in the call of dgetrf?

Thomas

Thomas,
ipiv is the array, but not integer
the dimention at least max(1,min(m,n)), therefore for your case ipiv[4].
Please refer to the mkl's reference manual.
--Gennady
0 Kudos
thomasdd
Beginner
1,856 Views

Thomas,
ipiv is the array, but not integer
the dimention at least max(1,min(m,n)), therefore for your case ipiv[4].
Please refer to the mkl's reference manual.
--Gennady
Thank you very much! Now it works fine. I was too fast in reading the reference :)

Thomas
0 Kudos
Reply