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

getrf and getri

Dan4
Beginner
298 Views
Hi,

I am doing a evaluation to be prepared to use MKL in our product. During this evaluation I have done a test to compare simple inversion of a matrix with another library. I have stored matrix data in a matrix called "P" with the dimensions of "nCells x nCells" and then called "getrf" and "getri" as below:

double *mklP;
mklP=new double[nCells*nCells];

for (int i=0; i for (int j=0; j mklP[i*nCells+j]=P(i, j);

int info;
int ipiv[nCells];
int lwork=-1;
double work[nCells];

dgetrf(&nCells, &nCells, mklP, &nCells, ipiv, &info);
dgetri(&nCells, mklP, &nCells, ipiv, work, &lwork, &info);

I have following questions:

1. Do I feed the "mklP" in correct way? I mean since the "mklP" is passed to MKL and it is just an array, do I feed it in a right way (mklP[i*nCells+j]=P(i, j)) ?

2. The result of matrix inversion will be stored in "mklP" but it is not correct at all! I do not know where I am doing wrong, but maybe some params are passed incorrectly ot "getrf" or "getri" functions. Can anybody help?

Thanks in advance,

D.

0 Kudos
4 Replies
TimP
Honored Contributor III
298 Views
Are you considering that subscripts of a 2D array with identical memory storage are reversed from Fortran (and MKL) to C? Do you want mklP[i+j*nCells]=P(i,j) ?
0 Kudos
Dan4
Beginner
298 Views
Quoting - tim18
Are you considering that subscripts of a 2D array with identical memory storage are reversed from Fortran (and MKL) to C? Do you want mklP[i+j*nCells]=P(i,j) ?


Hi,

Thanks for the tip. I changed the code as you said but the result is not still correct. When I multiply inverted matrix with original matrix the result is far far away from identity matrix. I am wodering if I am calling LAPACK functions correctly?

D.

0 Kudos
Melvin_Robinson
New Contributor I
298 Views
Quoting - danltu.se
Quoting - tim18
Are you considering that subscripts of a 2D array with identical memory storage are reversed from Fortran (and MKL) to C? Do you want mklP[i+j*nCells]=P(i,j) ?


Hi,

Thanks for the tip. I changed the code as you said but the result is not still correct. When I multiply inverted matrix with original matrix the result is far far away from identity matrix. I am wodering if I am calling LAPACK functions correctly?

D.

You have set LWORK to -1 which is just a workspace query. The function is returning without any actual inversion taking place. You might look at your info variable to see if this gives any good information if the call is still failing.
0 Kudos
Dan4
Beginner
298 Views
Quoting - Melvin
You have set LWORK to -1 which is just a workspace query. The function is returning without any actual inversion taking place. You might look at your info variable to see if this gives any good information if the call is still failing.

Exactly! Now I used returned values (after querying) to set lwork and it works fine now. Thanks for the tip.

0 Kudos
Reply