Community
cancel
Showing results for 
Search instead for 
Did you mean: 
psinclairegi_com
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?
0 Kudos
3 Replies
Gennady_F_Intel
Moderator
33 Views

please try to usecblas_dgemm() instead of dgemm().
Please look at this article. May be it will usefull.
--Gennady
psinclairegi_com
Beginner
33 Views

"...Be sure to store data Fortran-style, i.e. data stored column-major rather than row-major order. We recommend that C and C++ programmers use the CBLAS interface to avoid simple mistakes when following these conventions.."
Thank you very much. Works fine now.
Gennady_F_Intel
Moderator
33 Views

Thanks for the feedback. Precisely for these purposes and has been written this article.
--Gennady
Reply