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
초급자
2,660 조회수
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 포인트
1 솔루션
Gennady_F_Intel
중재자
2,660 조회수
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 포인트
4 응답
Melvin_Robinson
새로운 기여자 I
2,660 조회수
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 포인트
thomasdd
초급자
2,660 조회수
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 포인트
Gennady_F_Intel
중재자
2,661 조회수
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 포인트
thomasdd
초급자
2,660 조회수

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 포인트
응답