<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic mkl_blas DGEMM routine returns incorrect results in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-blas-DGEMM-routine-returns-incorrect-results/m-p/833159#M5792</link>
    <description>Hopefully this isn't a silly error on my part (most likely), but I've come up with a small code example in order to showcase what I feel is an incorrect result from MKL's BLAS 3 dgemm routine. See below:&lt;BR /&gt;&lt;BR /&gt; 1 #include &lt;CSTDLIB&gt;&lt;BR /&gt; 2 #include &lt;STDIO.H&gt;&lt;BR /&gt; 3 #include &lt;MKL_CBLAS.H&gt;&lt;BR /&gt; 4 &lt;BR /&gt; 5 &lt;BR /&gt; 6 void Print (double * m) {&lt;BR /&gt; 7 for (int i=0;i&amp;lt;3;i++) {&lt;BR /&gt; 8 for (int j=0;j&amp;lt;3;j++) {&lt;BR /&gt; 9 printf ("% 5.3f ", m[i+3*j]);&lt;BR /&gt;10 } &lt;BR /&gt;11 printf ("\\n");&lt;BR /&gt;12 } &lt;BR /&gt;13 printf ("\\n");&lt;BR /&gt;14 } &lt;BR /&gt;15 &lt;BR /&gt;16 &lt;BR /&gt;17 int main () {&lt;BR /&gt;18 &lt;BR /&gt;19 /* column-major order, as expected for the BLAS routines */&lt;BR /&gt;20 double h[9] = {4,3,2,3,4,2,1,2,3};&lt;BR /&gt;21 double k[9] = {4,3,2,3,4,2,1,2,3};&lt;BR /&gt;22 &lt;BR /&gt;23 printf ("-----\\nH:\\n");&lt;BR /&gt;24 Print(h);&lt;BR /&gt;25 &lt;BR /&gt;26 printf ("-----\\nK:\\n");&lt;BR /&gt;27 Print(k);&lt;BR /&gt;28 &lt;BR /&gt;29 cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, 3, 3, 3, 1.0, h, 3, k, 3, 0.0, k, 3);&lt;BR /&gt;30 &lt;BR /&gt;31 printf ("-----\\nK after dgemm:\\n");&lt;BR /&gt;32 Print(k);&lt;BR /&gt;33 return 0;&lt;BR /&gt;34 } &lt;BR /&gt;&lt;BR /&gt;I'm running this using MKL 10.2.5.035, using g++ 4.4.1 on a 32-bit i686 Linux box. Other MKL routines work splendidly (i.e. I've performed matrix inversion via LU decomposition successfully with the mkl_lapack routines).&lt;BR /&gt;&lt;BR /&gt;The result of this code is:&lt;BR /&gt;&lt;BR /&gt;-----&lt;BR /&gt;H:&lt;BR /&gt;4.000 3.000 1.000 &lt;BR /&gt;3.000 4.000 2.000 &lt;BR /&gt;2.000 2.000 3.000 &lt;BR /&gt;&lt;BR /&gt;-----&lt;BR /&gt;K:&lt;BR /&gt;4.000 3.000 1.000 &lt;BR /&gt;3.000 4.000 2.000 &lt;BR /&gt;2.000 2.000 3.000 &lt;BR /&gt;&lt;BR /&gt;-----&lt;BR /&gt;K after dgemm:&lt;BR /&gt;0.000 0.000 0.000 &lt;BR /&gt;0.000 0.000 0.000 &lt;BR /&gt;0.000 0.000 0.000 &lt;BR /&gt;&lt;BR /&gt;If I reverse the order of 'h' and 'k' in dgemm such that the call looks like:&lt;BR /&gt;29 cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, 3, 3, 3, 1.0, k, 3, h, 3, 0.0, k, 3);&lt;BR /&gt;&lt;BR /&gt;the change to the final "K after dgemm" looks like:&lt;BR /&gt;-----&lt;BR /&gt;K after dgemm:&lt;BR /&gt;11.000 167.000 1380.000 &lt;BR /&gt;16.000 244.000 2016.000 &lt;BR /&gt;12.000 186.000 1536.000 &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Both of these results are incorrect. Have I botched the call to the dgemm routine? Is this something more fundamental with the library?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;~Eric&lt;/MKL_CBLAS.H&gt;&lt;/STDIO.H&gt;&lt;/CSTDLIB&gt;</description>
    <pubDate>Fri, 27 Aug 2010 17:47:04 GMT</pubDate>
    <dc:creator>eshamay</dc:creator>
    <dc:date>2010-08-27T17:47:04Z</dc:date>
    <item>
      <title>mkl_blas DGEMM routine returns incorrect results</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-blas-DGEMM-routine-returns-incorrect-results/m-p/833159#M5792</link>
      <description>Hopefully this isn't a silly error on my part (most likely), but I've come up with a small code example in order to showcase what I feel is an incorrect result from MKL's BLAS 3 dgemm routine. See below:&lt;BR /&gt;&lt;BR /&gt; 1 #include &lt;CSTDLIB&gt;&lt;BR /&gt; 2 #include &lt;STDIO.H&gt;&lt;BR /&gt; 3 #include &lt;MKL_CBLAS.H&gt;&lt;BR /&gt; 4 &lt;BR /&gt; 5 &lt;BR /&gt; 6 void Print (double * m) {&lt;BR /&gt; 7 for (int i=0;i&amp;lt;3;i++) {&lt;BR /&gt; 8 for (int j=0;j&amp;lt;3;j++) {&lt;BR /&gt; 9 printf ("% 5.3f ", m[i+3*j]);&lt;BR /&gt;10 } &lt;BR /&gt;11 printf ("\\n");&lt;BR /&gt;12 } &lt;BR /&gt;13 printf ("\\n");&lt;BR /&gt;14 } &lt;BR /&gt;15 &lt;BR /&gt;16 &lt;BR /&gt;17 int main () {&lt;BR /&gt;18 &lt;BR /&gt;19 /* column-major order, as expected for the BLAS routines */&lt;BR /&gt;20 double h[9] = {4,3,2,3,4,2,1,2,3};&lt;BR /&gt;21 double k[9] = {4,3,2,3,4,2,1,2,3};&lt;BR /&gt;22 &lt;BR /&gt;23 printf ("-----\\nH:\\n");&lt;BR /&gt;24 Print(h);&lt;BR /&gt;25 &lt;BR /&gt;26 printf ("-----\\nK:\\n");&lt;BR /&gt;27 Print(k);&lt;BR /&gt;28 &lt;BR /&gt;29 cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, 3, 3, 3, 1.0, h, 3, k, 3, 0.0, k, 3);&lt;BR /&gt;30 &lt;BR /&gt;31 printf ("-----\\nK after dgemm:\\n");&lt;BR /&gt;32 Print(k);&lt;BR /&gt;33 return 0;&lt;BR /&gt;34 } &lt;BR /&gt;&lt;BR /&gt;I'm running this using MKL 10.2.5.035, using g++ 4.4.1 on a 32-bit i686 Linux box. Other MKL routines work splendidly (i.e. I've performed matrix inversion via LU decomposition successfully with the mkl_lapack routines).&lt;BR /&gt;&lt;BR /&gt;The result of this code is:&lt;BR /&gt;&lt;BR /&gt;-----&lt;BR /&gt;H:&lt;BR /&gt;4.000 3.000 1.000 &lt;BR /&gt;3.000 4.000 2.000 &lt;BR /&gt;2.000 2.000 3.000 &lt;BR /&gt;&lt;BR /&gt;-----&lt;BR /&gt;K:&lt;BR /&gt;4.000 3.000 1.000 &lt;BR /&gt;3.000 4.000 2.000 &lt;BR /&gt;2.000 2.000 3.000 &lt;BR /&gt;&lt;BR /&gt;-----&lt;BR /&gt;K after dgemm:&lt;BR /&gt;0.000 0.000 0.000 &lt;BR /&gt;0.000 0.000 0.000 &lt;BR /&gt;0.000 0.000 0.000 &lt;BR /&gt;&lt;BR /&gt;If I reverse the order of 'h' and 'k' in dgemm such that the call looks like:&lt;BR /&gt;29 cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, 3, 3, 3, 1.0, k, 3, h, 3, 0.0, k, 3);&lt;BR /&gt;&lt;BR /&gt;the change to the final "K after dgemm" looks like:&lt;BR /&gt;-----&lt;BR /&gt;K after dgemm:&lt;BR /&gt;11.000 167.000 1380.000 &lt;BR /&gt;16.000 244.000 2016.000 &lt;BR /&gt;12.000 186.000 1536.000 &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Both of these results are incorrect. Have I botched the call to the dgemm routine? Is this something more fundamental with the library?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;~Eric&lt;/MKL_CBLAS.H&gt;&lt;/STDIO.H&gt;&lt;/CSTDLIB&gt;</description>
      <pubDate>Fri, 27 Aug 2010 17:47:04 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-blas-DGEMM-routine-returns-incorrect-results/m-p/833159#M5792</guid>
      <dc:creator>eshamay</dc:creator>
      <dc:date>2010-08-27T17:47:04Z</dc:date>
    </item>
    <item>
      <title>mkl_blas DGEMM routine returns incorrect results</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-blas-DGEMM-routine-returns-incorrect-results/m-p/833160#M5793</link>
      <description>The DGEMM routine takes three matrices A,B,C and two scalars \alpha and \beta as input, computes the expression \alpha op(A).op(B) + \beta C, and returns the result in C. &lt;BR /&gt;&lt;BR /&gt;You have aliased A and C, since you use k in their place. The result is 'implementation dependent'. You should not cause input arguments to clobber one another.&lt;BR /&gt;&lt;BR /&gt;The MKL implementation has this feature. If \beta is zero, as in your example, C need not be set initially, since MKL will notice that \beta is zero, and zero out C before adding \alpha op(A).op(B). However, that has the effect of zeroing your A before it got used, since you made A and C one and the same; that is why the result is a null matrix.&lt;BR /&gt;&lt;BR /&gt;Use another matrix, R, say, in place of the 13th argument, and print that after DGEMM has finished. You will get the correct result.&lt;BR /&gt;&lt;BR /&gt;BLAS routines have been used millions of times over many decades. It is very improbable that errors in them would have remained unnoticed for so long!</description>
      <pubDate>Fri, 27 Aug 2010 23:50:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-blas-DGEMM-routine-returns-incorrect-results/m-p/833160#M5793</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2010-08-27T23:50:17Z</dc:date>
    </item>
  </channel>
</rss>

