<?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_sparse_d_mm() wrong results in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-sparse-d-mm-wrong-results/m-p/1188704#M29704</link>
    <description>&lt;P&gt;Hello everybody,&lt;/P&gt;
&lt;P&gt;I ran into wrong results when I was trying to use mkl_sparse_d_mm() to multiply a symmetric sparse matrix A [12 x 12]&amp;nbsp; (CSR packed, lower triangular) by a dense rectangular matrix B [12 x 3] (full), that is:&lt;/P&gt;
&lt;P&gt;C = A * B&lt;/P&gt;
&lt;P&gt;Both matrices A and B have column wise layout, while the A matrix's CSR indeces arrays are all 0-based.&lt;/P&gt;
&lt;P&gt;Here the example code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;int main() 
{ 
   // sparse matrix A[12x12] (lower triangular, column wise layout, 0-based indexing) 
   struct matrix_descr A_descr; 
   A_descr.type = SPARSE_MATRIX_TYPE_TRIANGULAR; 
   A_descr.mode = SPARSE_FILL_MODE_LOWER; 
   A_descr.diag = SPARSE_DIAG_NON_UNIT; 

   // A rows_start 
   MKL_INT A_ptrb[12] = { 0, 3, 8, 12, 14, 17, 20, 22, 25, 27, 28, 29 }; 
   // A rows_end 
   MKL_INT A_ptre[12] = { 3, 8, 12, 14, 17, 20, 22, 25, 27, 28, 29, 30 }; 

   // A column_indeces 
   MKL_INT A_col_index[30] = { 0, 4, 6, 1, 3, 5, 7, 11, 2, 4, 8, 10, 3, 9, 4, 8, 10, 5, 7, 11, 6, 10, 7, 9, 11, 8, 10, 9, 10, 11 }; 

   // A values
   double A_values[30] = { 3.60394e+06, -2.27463e+07, -3.14901e+06, 462747, 2.27463e+07, -1.56399e+06, -7819.96, -1.56399e+06, 1.26039e+07, 1.56399e+06, -7819.96, 1.56399e+06, 1.63638e+09, -7.91937e+07, 1.97495e+09, -1.56399e+06, 2.07831e+08, 7.3454e+08, 1.56399e+06, 2.07831e+08, 3.60394e+06, -2.27463e+07, 462747, 2.27463e+07, 1.56399e+06, 1.26039e+07, -1.56399e+06, 1.63638e+09, 1.97495e+09, 7.3454e+08 };

   // handle to A matrix
   sparse_matrix_t A_handle;
   sparse_status_t outcome = mkl_sparse_d_create_csr(&amp;amp;A_handle, SPARSE_INDEX_BASE_ZERO, 12, 12, A_ptrb, A_ptre, A_col_index, A_values); 

   // dense matrix B [12x3] values (full, column wise layout) 
   double B[36] = { 0.447212, 0, -0.00115627, 0, 0.00466197, 0, 0.447212, 0, 0.00115627, 0, 0.00466197, 0, 3.77898e-21, 0, -0.447214, 0, 5.05844e-22, 0, 6.67055e-22, 0, -0.447214, 0, -4.18026e-22, 0, 0, 0.447214, 0, -0.00653261, 0, -3.29415e-20, 0, 0.447214, 0, -0.00653261, 0, -3.44084e-21 }; 

   // C = A * B double C[36]; 
   mkl_sparse_d_mm(SPARSE_OPERATION_NON_TRANSPOSE, 1.0, A_handle, A_descr, SPARSE_LAYOUT_COLUMN_MAJOR, B, 3, 12, 0.0, C, 12); 

   // print C 
   for (size_t r = 0; r != 12; r++) 
   { 
      for (size_t c = 0; c != 3; c++) 
         std::cout &amp;lt;&amp;lt; C[r + 12*c] &amp;lt;&amp;lt; " "; 
      std::cout &amp;lt;&amp;lt; std::endl; 
   } 
   return 0; 
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Could it be a problem with the triangular form assigned to the CSR matrix?&amp;nbsp; Does the routine need the full CSR matrix maybe? The results seem to be correct if the sparse matrix has no off-diagonal terms (i.e. it it's diagonal).&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Jul 2020 08:49:40 GMT</pubDate>
    <dc:creator>di_luca__daniele1</dc:creator>
    <dc:date>2020-07-01T08:49:40Z</dc:date>
    <item>
      <title>mkl_sparse_d_mm() wrong results</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-sparse-d-mm-wrong-results/m-p/1188704#M29704</link>
      <description>&lt;P&gt;Hello everybody,&lt;/P&gt;
&lt;P&gt;I ran into wrong results when I was trying to use mkl_sparse_d_mm() to multiply a symmetric sparse matrix A [12 x 12]&amp;nbsp; (CSR packed, lower triangular) by a dense rectangular matrix B [12 x 3] (full), that is:&lt;/P&gt;
&lt;P&gt;C = A * B&lt;/P&gt;
&lt;P&gt;Both matrices A and B have column wise layout, while the A matrix's CSR indeces arrays are all 0-based.&lt;/P&gt;
&lt;P&gt;Here the example code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;int main() 
{ 
   // sparse matrix A[12x12] (lower triangular, column wise layout, 0-based indexing) 
   struct matrix_descr A_descr; 
   A_descr.type = SPARSE_MATRIX_TYPE_TRIANGULAR; 
   A_descr.mode = SPARSE_FILL_MODE_LOWER; 
   A_descr.diag = SPARSE_DIAG_NON_UNIT; 

   // A rows_start 
   MKL_INT A_ptrb[12] = { 0, 3, 8, 12, 14, 17, 20, 22, 25, 27, 28, 29 }; 
   // A rows_end 
   MKL_INT A_ptre[12] = { 3, 8, 12, 14, 17, 20, 22, 25, 27, 28, 29, 30 }; 

   // A column_indeces 
   MKL_INT A_col_index[30] = { 0, 4, 6, 1, 3, 5, 7, 11, 2, 4, 8, 10, 3, 9, 4, 8, 10, 5, 7, 11, 6, 10, 7, 9, 11, 8, 10, 9, 10, 11 }; 

   // A values
   double A_values[30] = { 3.60394e+06, -2.27463e+07, -3.14901e+06, 462747, 2.27463e+07, -1.56399e+06, -7819.96, -1.56399e+06, 1.26039e+07, 1.56399e+06, -7819.96, 1.56399e+06, 1.63638e+09, -7.91937e+07, 1.97495e+09, -1.56399e+06, 2.07831e+08, 7.3454e+08, 1.56399e+06, 2.07831e+08, 3.60394e+06, -2.27463e+07, 462747, 2.27463e+07, 1.56399e+06, 1.26039e+07, -1.56399e+06, 1.63638e+09, 1.97495e+09, 7.3454e+08 };

   // handle to A matrix
   sparse_matrix_t A_handle;
   sparse_status_t outcome = mkl_sparse_d_create_csr(&amp;amp;A_handle, SPARSE_INDEX_BASE_ZERO, 12, 12, A_ptrb, A_ptre, A_col_index, A_values); 

   // dense matrix B [12x3] values (full, column wise layout) 
   double B[36] = { 0.447212, 0, -0.00115627, 0, 0.00466197, 0, 0.447212, 0, 0.00115627, 0, 0.00466197, 0, 3.77898e-21, 0, -0.447214, 0, 5.05844e-22, 0, 6.67055e-22, 0, -0.447214, 0, -4.18026e-22, 0, 0, 0.447214, 0, -0.00653261, 0, -3.29415e-20, 0, 0.447214, 0, -0.00653261, 0, -3.44084e-21 }; 

   // C = A * B double C[36]; 
   mkl_sparse_d_mm(SPARSE_OPERATION_NON_TRANSPOSE, 1.0, A_handle, A_descr, SPARSE_LAYOUT_COLUMN_MAJOR, B, 3, 12, 0.0, C, 12); 

   // print C 
   for (size_t r = 0; r != 12; r++) 
   { 
      for (size_t c = 0; c != 3; c++) 
         std::cout &amp;lt;&amp;lt; C[r + 12*c] &amp;lt;&amp;lt; " "; 
      std::cout &amp;lt;&amp;lt; std::endl; 
   } 
   return 0; 
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Could it be a problem with the triangular form assigned to the CSR matrix?&amp;nbsp; Does the routine need the full CSR matrix maybe? The results seem to be correct if the sparse matrix has no off-diagonal terms (i.e. it it's diagonal).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jul 2020 08:49:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-sparse-d-mm-wrong-results/m-p/1188704#M29704</guid>
      <dc:creator>di_luca__daniele1</dc:creator>
      <dc:date>2020-07-01T08:49:40Z</dc:date>
    </item>
  </channel>
</rss>

