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

pdgetrf in mixed language

phaser75
Beginner
460 Views
I exercise LAPACK in c language. I want to factorize a matrix(2X2) but it doesn't work.
I don't have any idea what is the problem.
The simple code is like this. The error message says there is a problem in 4th parameter(lda).

#include
#include
#include "mkl.h"

#define NRANSI
#include "NRUTIL.h"

#define PI (3.141592653589793)

int main(int argc, char* argv[])
{
int m, n, lda, info;
double **A, d;
int *ipiv;

A = dmatrix(1,2,1,2);
ipiv = ivector(1,2);

m = 2;
n = 2;
lda = 2;
A[1][1] = 4.0;
A[1][2] = 1.0;
A[2][1] = 3.0;
A[2][2] = -1.0;

printf("This is TEST!!!\n");

dgetrf(&m, &n, &A[1][1], &lda, &ipiv[1], &info);
printf("info = %d\n",info);

free_dmatrix(A,1,2,1,2);
free_ivector(ipiv,1,2);

return 1;
}
0 Kudos
8 Replies
Gennady_F_Intel
Moderator
460 Views
Quoting - phaser75
I exercise LAPACK in c language. I want to factorize a matrix(2X2) but it doesn't work.
I don't have any idea what is the problem.
The simple code is like this. The error message says there is a problem in 4th parameter(lda).

#include
#include
#include "mkl.h"

#define NRANSI
#include "NRUTIL.h"

#define PI (3.141592653589793)

int main(int argc, char* argv[])
{
int m, n, lda, info;
double **A, d;
int *ipiv;

A = dmatrix(1,2,1,2);
ipiv = ivector(1,2);

m = 2;
n = 2;
lda = 2;
A[1][1] = 4.0;
A[1][2] = 1.0;
A[2][1] = 3.0;
A[2][2] = -1.0;

printf("This is TEST!!!n");

dgetrf(&m, &n, &A[1][1], &lda, &ipiv[1], &info);
printf("info = %dn",info);

free_dmatrix(A,1,2,1,2);
free_ivector(ipiv,1,2);

return 1;
}


please try in that way:

A[0][0] = 4.0;
A[0][1] = 1.0;
A[1][0] = 3.0;
A[1][1] = -1.0;

dgetrf(&m, &n, &A[0][0], &lda, &ipiv[1], &info);

it should work.

--Gennady
0 Kudos
phaser75
Beginner
460 Views
Quoting - phaser75
I still have the error.
The message is "MKL ERROR : Parameter 4 was incorrect on entry to DGETRF
info = -4".
0 Kudos
Gennady_F_Intel
Moderator
460 Views
Quoting - phaser75
I exercise LAPACK in c language. I want to factorize a matrix(2X2) but it doesn't work.
I don't have any idea what is the problem.
The simple code is like this. The error message says there is a problem in 4th parameter(lda).

#include
#include
#include "mkl.h"

#define NRANSI
#include "NRUTIL.h"

#define PI (3.141592653589793)

int main(int argc, char* argv[])
{
int m, n, lda, info;
double **A, d;
int *ipiv;

A = dmatrix(1,2,1,2);
ipiv = ivector(1,2);

m = 2;
n = 2;
lda = 2;
A[1][1] = 4.0;
A[1][2] = 1.0;
A[2][1] = 3.0;
A[2][2] = -1.0;

printf("This is TEST!!!n");

dgetrf(&m, &n, &A[1][1], &lda, &ipiv[1], &info);
printf("info = %dn",info);

free_dmatrix(A,1,2,1,2);
free_ivector(ipiv,1,2);

return 1;
}


please try in that way:

A[0][0] = 4.0;
A[0][1] = 1.0;
A[1][0] = 3.0;
A[1][1] = -1.0;

dgetrf(&m, &n, &A[0][0], &lda, &ipiv[1], &info);

it should work.

--Gennady

the same with &ipiv[0] not &ipiv[1]
0 Kudos
phaser75
Beginner
460 Views

the same with &ipiv[0] not &ipiv[1]
Thank you for replying but it still doesn't work. Error message is same.

0 Kudos
ArturGuzik
Valued Contributor I
460 Views
Quoting - phaser75
Thank you for replying but it still doesn't work. Error message is same.


Hi,

check this thread. You have double indexed matrices here.

for statically allocated matrices example of using LAPACK is here.

A.
0 Kudos
phaser75
Beginner
460 Views
Quoting - ArturGuzik

Hi,

check this thread. You have double indexed matrices here.

for statically allocated matrices example of using LAPACK is here.

A.
Thank you. But it is the same.
I tried static allocation and one dimensional array as well. But the same error occurred.
What's the problem?

phaser.
0 Kudos
ArturGuzik
Valued Contributor I
460 Views
Quoting - phaser75
Thank you. But it is the same.
I tried static allocation and one dimensional array as well. But the same error occurred.
What's the problem?

phaser.
OK then. This is working for me (static for simplicity).

[cpp]//
#include
#include "mkl_lapack.h"
#define MAX 2

int main(){

// data
int n, m;
int nrhs = 1;
double A[MAX][MAX];
double b[1][MAX];
int lda = MAX;
int ldb = MAX;
int ipiv[MAX];
int info;
// Other values
int i,j;

// dimension(s)
m=2;
n=2;

// value(s)
A[0][0] = 2.0;
A[0][1] = 0.0;
A[1][0] = 0.0;
A[1][1] = -2.0;
b[0][0]=1.0;
b[0][1]=2.0;

// factorize
dgetrf(&m, &n, &A[0][0], &lda, &ipiv[0], &info);
// solve
dgetrs("N", &n, &nrhs, &A[0][0], &lda, &ipiv[0], &b[0][0], &ldb, &info);

// Check for success
if(info == 0)
{
// Write the answer
std::cout << "The answer isn";
for(i = 0; i < n; i++)
std::cout << "b[" << i << "]t" << b[0] << "n";
}
else
{
// Write an error message
std::cerr << "dgetrf returned error " << info << "n";
}

return info;
}
[/cpp]

A.
0 Kudos
redleaf
Beginner
460 Views
I've got the same problem with using the MKL library.
I've just found out that the problem lies in the parameters' data type.
Actually there's some incompatibility between Int32 and Int64.
Declared as MKL_INT, variables were interpreted as Int32 at compile time.
Nevertheless it was linked with the mkl_intel_ilp64, hence when I pass the address of an "int" instead of a "long int", the function might get a zero value. In this case the matrix leading. It leads to this error.
The problem is solved by simply changing the type of lda, m and n to long int.
0 Kudos
Reply