Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
6977 Discussions

Initializing matrices for dgemm (beginner question)

psinclairegi_com
Beginner
263 Views
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
263 Views
please try to usecblas_dgemm() instead of dgemm().
Please look at this article. May be it will usefull.
--Gennady
0 Kudos
psinclairegi_com
Beginner
263 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.
0 Kudos
Gennady_F_Intel
Moderator
263 Views
Thanks for the feedback. Precisely for these purposes and has been written this article.
--Gennady
0 Kudos
Reply