- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Library version: 2021.3
- OS info and version: CentOS 7.9.2009
- Compiler verison: icc version 2021.3.0 (gcc version 4.8.5 compatibility)
- MKL linking command:

`icc -O2 -std=c11 -mkl=sequential -L$MKLROOT/lib/intel64 dgemm.c -o dgemm.x`

Dear Support Team,

I am measuring performance of matrix multiplication using dgemm().

The code to reproduce the issue is attached. dgemm() was invoked as following:

`dgemm("N", "N", &m, &n, &p, &alpha, A, &p, B, &n, &beta, C, &n);`

The example is a simple 3x3 multiplication. In the source code, there are two ways to initialize A and B. I marked these two methods with approriate comments in the file.

- Double casting of interger: this gives correct C
- Random number between (0,1]: this gives incorrect C

To rule out the possibility of thread interference, I linked with the sequential version of the library.

The file 'correct.txt' is the expected output for randomized input matrices.

The file 'incorrect.txt' is the result I obtained with dgemm() for randomized input matrices

I appreciate if you can point me to the origin of this inconsistency.

- dgemm.c: https://justpaste.it/7zhsb
- correct.txt: https://justpaste.it/6mizg
- incorrect.txt: https://justpaste.it/5g7bi

(For some reason, I could not attach the files using forum, I appologize for the inconvenience)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi,

Thanks for reaching out to us.

We tried the provided code from our end and could reproduce the results which you are getting.

But here are some observations:

To check the results we used cblas_dgemm where you will get an option to change the matrix layout (Row Major or Col Major)

Here is the function call

`cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, m, n, p, alpha, A, p, B, n, beta, C, n);`

By using the above function call, we observed it is giving the correct result (matches with your expected result)

`cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, m, n, p, alpha, A, p, B, n, beta, C, n);`

whereas the above function call gives the output which matches with your incorrect result.

*>>dgemm("N", "N", &m, &n, &p, &alpha, A, &p, B, &n, &beta, C, &n);*

By default dgemm follows the matrix layout as column-major, hence there is a mismatch in your expected and actual results.

Please find the attached file for the code snippet we have tried.

Hope the provided information helped.

Regards,

Vidya.

Link Copied

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi,

Thanks for reaching out to us.

We tried the provided code from our end and could reproduce the results which you are getting.

But here are some observations:

To check the results we used cblas_dgemm where you will get an option to change the matrix layout (Row Major or Col Major)

Here is the function call

`cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, m, n, p, alpha, A, p, B, n, beta, C, n);`

By using the above function call, we observed it is giving the correct result (matches with your expected result)

`cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, m, n, p, alpha, A, p, B, n, beta, C, n);`

whereas the above function call gives the output which matches with your incorrect result.

*>>dgemm("N", "N", &m, &n, &p, &alpha, A, &p, B, &n, &beta, C, &n);*

By default dgemm follows the matrix layout as column-major, hence there is a mismatch in your expected and actual results.

Please find the attached file for the code snippet we have tried.

Hope the provided information helped.

Regards,

Vidya.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Dear Vidya,

Thanks for the detailed answer and test. I am able to obtain correct result using cblas_dgemm as you suggested.

Regards.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi,

Thanks for accepting our solution.

As this issue is resolved, we are closing this thread. Please post a new question if you need any additional information from Intel as this thread will no longer be monitored.

Have a Good Day!

Regards,

Vidya.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page