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

## Initializing matrices for dgemm (beginner question)

I would expect the following C code...

double a[3*3] = { 0.3804, -0.7225, 0.5774,

-0.8159, 0.0318, 0.5774,

0.4355, 0.6907, 0.5774};

double b[3*6] = { 1.0006, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,

0.0000, 0.4887, 0.0000, 0.0000, 0.0000, 0.0000,

0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000};

double c[3*6] = { 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,

0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,

0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000};

int m = 3;

int n = 6;

int k = 3;

double alpha = 1;

double beta = 0;

int lda = m;

int ldb = k;

int ldc = m;

dgemm("N", "N", &m, &n, &k, α, a, &lda, b, &ldb, β, c, &ldc);

...to fill matrix c with:

0.3806, -0.3531, 0.0000, 0.0000, 0.0000, 0.0000,

-0.8164, 0.0155, 0.0000, 0.0000, 0.0000, 0.0000,

0.4358, 0.3375, 0.0000, 0.0000, 0.0000, 0.0000

My own matrix multiplication code does this, MATLAB does this, and the first 2 matrix multiplication apps that I tried online produced the above result. (http://www.bluebit.gr/matrix-calculator/matrix_multiplication.aspx)
dgemm will only return a similar result if I first transpose matrix a (it returns the same numbers but transposed). What am I doing wrong?
3 Replies
Moderator
33 Views