- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear all,
I am writing code to process mat multiply. And I write a little program to test the result of zgemm. But the result is incorrect and I do not really know the reason. I write code on my labtop. -i7 64bit windows8 visual studio 2010 mkl 10.0.3.021
Here is the code. The size of A is 3*2 and the size of B is 2*2 which is a unit matrix. I think the result is A itself but it seems not.
int main()
{
int *m =new int; //m*n n*k
int *n =new int;
int *k =new int;
*m =3;
*n = 2;
*k = 2;
MKL_Complex16 *A = new MKL_Complex16 [6];
MKL_Complex16 *B = new MKL_Complex16 [4];
MKL_Complex16 *N = new MKL_Complex16 [4];
A[0].real = 1;
A[1].real = 2;
A[2].real = 3;
A[3].real = 4;
A[4].real = 5;
A[5].real = 6;
for(int i=0; i<6; i++) A.imag =0;
B[0].real = 1;
B[1].real = 0;
A[2].real = 0;
A[3].real = 1;
for(int i=0; i<4; i++) B.imag =0;
MKL_Complex16 *alpha = new MKL_Complex16;
MKL_Complex16 *beta = new MKL_Complex16;
MKL_Complex16 cAlpha = {1,0}, cBeta = {0,0};
alpha = &cAlpha;
beta = &cBeta;
zgemm("n","n",m,k,n,alpha,A,m,B,n,beta,N,m);
for(int i=0;i<6;i++) std::cout<<(N+i)<<" "<<N.real<<" "<<N.imag<<std::endl;
getchar();
return 0;
}
I do not know whether I output the result in a right way. I really need help. Thank all of you a lot!!
Claire
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did you really mean A here, not B?
A[2].real = 0;
A[3].real = 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wanted to ask the same question:-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Claire,
Anther notes for the this code that zgem is fortran interface. You are calling the fortran function in a C code, the A/B/C array is assumed as the column-major data. For example, the A in this code, the actually matrix data is:
1 4
2 5
3 6
If you want to use the C function, you can call cblas function.
Thanks,
Chao
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
crispybits wrote:
Did you really mean A here, not B?
A[2].real = 0;
A[3].real = 1
I find my mistake here. It should be B's value. Thank you. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Chao Y (Intel) wrote:
Claire,
Anther notes for the this code that zgem is fortran interface. You are calling the fortran function in a C code, the A/B/C array is assumed as the column-major data. For example, the A in this code, the actually matrix data is:
1 4
2 5
3 6If you want to use the C function, you can call cblas function.
Thanks,
Chao
I always have questions about the sequence of the matrix's values are saved. According to your description, the address adds with priority in the column direction from up to down, right? I used to writing codes with MATLAB and it seems that they saved the value in same sequence. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
iliyapolak wrote:
Wanted to ask the same question:-)
C almost drive me crazy!! Have you gotten the solution to your problem?

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page