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

problem about LAPACKE_dgetrf and LAPACKE_dgetri

HM_Li
Beginner
1,125 Views

Please see attachment  b.c.

if I comment out from //hmli begin to  //hmli end in the follow code of b.c, it works wrong, but if I do not comment out and use sprintf and atof to convert from double to string, then convert back to double, it work well. 

for (k = 0; k < 64; k++)a +=(double) A1 * A1;
//hmli begin
sprintf(t,"%lf",a);
a=atof(t);
//hmli end
a = (double)a;

Is it just because of the precision?

Can you help me? Thank you very much.

  • b.c: source code
  • body.log : input data file
  • ainv.log: result of matrix inversion.
  • compiling :icc -mkl b.c

 

 

0 Kudos
1 Solution
Alexander_K_Intel3
1,125 Views

Hello,

The input matrix in the example is very ill-conditioned. This means it hardly could lead to an accurate result, and round-offs cause big fluctuation of the output.

As I see the best option here is to improve the condition number of the input matrix.
However you also could try dgesvxx with FACT=E. This way the function does normalization and equlibration of input data, which could improve accuracy for ill-conditioned matrices. Please provide and identity matrix NxN in B, and on output B will contain inverse of matrix A. Or the function will return a warning in INFO (see documentation) if the matrix is too ill-conditioned.

Best regards,
Alexander

View solution in original post

0 Kudos
4 Replies
mecej4
Honored Contributor III
1,125 Views

You are methodically destroying the precision of the input matrix. Take the (1,1) element of A, for example. It has the value 5.2734375...e-002. After your strange manipulation, the 15+ digit precision of A1,1  has been degraded to just five significant digits, i.e, it is now 5.2734000e-002. What is the purpose of writing a limited number of digits and reading the truncated number back in?

0 Kudos
HM_Li
Beginner
1,125 Views

Thank you.

The reason is: if the double float data not truncated, LAPACKE_dgetrf and LAPACKE_dgetri can't give the right result, so I want to know why and how to use LAPACKE_dgetrf and LAPACKE_dgetri right.

0 Kudos
Alexander_K_Intel3
1,126 Views

Hello,

The input matrix in the example is very ill-conditioned. This means it hardly could lead to an accurate result, and round-offs cause big fluctuation of the output.

As I see the best option here is to improve the condition number of the input matrix.
However you also could try dgesvxx with FACT=E. This way the function does normalization and equlibration of input data, which could improve accuracy for ill-conditioned matrices. Please provide and identity matrix NxN in B, and on output B will contain inverse of matrix A. Or the function will return a warning in INFO (see documentation) if the matrix is too ill-conditioned.

Best regards,
Alexander

0 Kudos
HM_Li
Beginner
1,125 Views

Thank you very much. I see.

0 Kudos
Reply