# Is there a problem with hemm() ?

## Is there a problem with hemm() ?

If I multiply two complex diagonal 2x2 matrices, with chemm(), I don't get a diagonal matrix !

Here is the code for C=A.B

Matrix A is stored as an upper triangle hermitian matrix.

#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <complex>
#include <math.h>

#define MKL_Complex8 std::complex<float>
#define MKL_INT int
#include "mkl.h"
using namespace std;
typedef std::complex<float> Comp ;
int main(int argc, char** argv)
{
CBLAS_ORDER order= CblasColMajor;
CBLAS_SIDE Left = CblasLeft;
CBLAS_UPLO Uplo= CblasUpper;
Comp one=1; Comp zero =0;
Comp A[3];
Comp B[4];
Comp C[4];
A[0]=1.0;A[1]=0;A[2]=1.0;
B[0]=2.0;B[1]=0;B[2]=2.0;B[3]=0;
cblas_chemm ( order,  Left, Uplo, 2, 2, &one, A, 2, B, 2, &zero, C, 2); //C=A.B

for (int i=0;i<2;i++)
{
for (int j=0;j<2;j++)
cout<<C[i+2*j]<<"  ";
cout<<endl;
}

}

4 posts / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.

The convention is that you must allocate space for the entire matrix, even though you may fill in only the upper or lower triangle. There is no special provision for diagonal matrices.

Therefore, correct your code to change the declaration of A to A[4] and set the values as

```A[0]=1.0;A[1]=0;A[2]=0.0; A[3]=1.0;

B[0]=2.0;B[1]=0;B[2]=0.0; B[3]=1.0;```

Thanks Mecej4.