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

## cblas_zsyrk returns wrong results

I have the following function and I'm trying to compute C = A*A' using zsyrk from blas, but when I print the C matrix the results are wrong. What am I missing?

```double* zsyrk(int N, double *A) {

int i,j;

int K;
K = N;

const int * alpha;
int a = 1;
alpha = &a;

int lda = N;
int ldc = N;

const int * beta;
int b = 0;
beta = &b;

double *C;
C = (double *)calloc( N*N, sizeof(double));

for (i = 0; i < N; i++){
for(j = 0; j < N; j++){
printf("%lf ", A[i*N + j]);
}
printf("\n");
}

cblas_zsyrk(CblasRowMajor, CblasUpper, CblasTrans, N, K, alpha, A, lda, beta, C, ldc);

for (i = 0; i < N; i++){
for(j = 0; j < N; j++){
printf("%lf ", C[i*N + j]);
}
printf("\n");
}

return C;
}```

The restults are:

Matrix A:

-662.059957 -942.824833
545.621059 -270.699577

Matrix C:
-0.000000 0.000000
0.000000 -0.000000

3 Replies Employee
87 Views

Hi Andrews,

are the array A complex number or double array?
How about try cblas_dsyrk  to replace the cblas_zsyrk

Best regards,
Ying

BLAS routine names have the following structure:
<character> <name> <mod> ( )
The <character> field indicates the data type:

 s real, single precision c complex, single precision

 d real, double precision z complex, double precision Beginner
87 Views

Hej,

Instead of int declare both  constants, alpha and beta, as double

e.g.

 `const` `double` `* alpha;`
 `09` `    ``double` `a = 1;`
 `10` `    ``alpha = &a;`

Also, in order to calculate C as C = A*A' (+yada yada) ,  you have to use CblasNoTrans instead of CblasTrans (check the documentation).

Now everything will work just as intended.

Regards,

Petru Beginner
87 Views

Hej,

In order to calculate correctly you have to:

1. change the alpha and beta constants from int to double.

e.g.

 `1` `    ``const` `double` `* alpha;`
 `2` `    ``double` `a = 1;`
 `3` `    ``alpha = &a;`

 `4`
 `5` `    ``const` `double` `* beta;`
 `6` `    ``double` `b = 0;`
 `7` `    ``beta = &b;`

2. change CblasTrans to CblasNoTrans (check the documentation)

Regards,

Petru 