Community
cancel
Showing results for
Did you mean:
Beginner
63 Views

GETRS problem

Dear all,

I am trying to use ZGETRF+ZGETRS function to solve a square matrix equation in form of Ax=b but the results are totally different comparign with results from GMM++. I use the code below in C++ and Linux:

// MKL solution to solve "YV=I" matrix equation
int info;
int ipiv[nNodes];
int nrhs=1;
char transa='N';

zgetrf(&nNodes, &nNodes, MKL_Y, &nNodes, ipiv, &info);
zgetrs(&transa, &nNodes, &nrhs, MKL_Y, &nNodes, ipiv, &I[0], &nNodes, &info);

where I is defined as

vector > I(nNodes);

and filled before above functions are called. nNodes also indicates the dimension of "A" which is square.

Have you had same experience before? Any help would be appreciated.

Thanks,

D.

3 Replies
Black Belt
63 Views
You have to use the same double complex type as that used in building MKL, that is, the MKL_Complex16. Other conventions for representing complex numbers in C++ may not be type-compatible.

You are more likely to get help if you show a small complete example with source code and particulars about your environment (OS, compiler and special library versions).

Here is a small example that works with ICPC 11.1.072. Please note that ZGETRF and ZGETRS are to be called using the expected Fortran calling convention.

`[cpp]#include extern "C" {#include #include"mkl_lapack.h"}using namespace std;main(){int i,j,N=2;MKL_Complex16 *A,*B; int info,*ipiv,nrhs=1;double x,y;A = new MKL_Complex16[N*N];B = new MKL_Complex16;ipiv = new int;for(i=0; i  scanf("%lf,%lf",&x,&y);  A.real=x; A.imag=y;  }for(i=0; i  scanf("%lf,%lf",&x,&y);  B.real=x; B.imag=y;  }zgetrf(&N,&N,A,&N,ipiv,&info);zgetrs("N",&N,&nrhs,A,&N,ipiv,B,&N,&info);for(i=0; i.real,B.imag);}[/cpp]`
When compiled and run with the input data
`[bash]4,1 -2,-1 -1,-1 7,15,-4 17,-4[/bash]`
it gives the expected result
`[bash] 2.000e+00 + -1.000e+00 i 3.000e+00 + -1.000e+00 i[/bash]`
Moderator
63 Views
see the similar topic has been discussed hereas well