<?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 Re: mkl_sparse_sp2m Issue C++ in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-sparse-sp2m-Issue-C/m-p/1342769#M32416</link>
    <description>&lt;P&gt;Hi David,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for reaching out to us.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output column/row indices for sp2m are not sorted, this is implied by the algorithm currently used.&lt;/P&gt;
&lt;P&gt;In order to sort the indices, you can call&lt;STRONG&gt; mkl_sparse_order&lt;/STRONG&gt; for the resultant matrix (here it is B) after using mkl_sparse_sp2m.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just insert the mkl_sparse_order function as below in your code&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;std::cout &amp;lt;&amp;lt; "Result:" &amp;lt;&amp;lt; std::endl;
checkStat(mkl_sparse_order (B));
outputCsr(B);&lt;/LI-CODE&gt;
&lt;P&gt;After making the above changes, recompile the code and you will get the expected results.&lt;/P&gt;
&lt;P&gt;Please do let us know if you face any issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Vidya.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Dec 2021 10:23:29 GMT</pubDate>
    <dc:creator>VidyalathaB_Intel</dc:creator>
    <dc:date>2021-12-09T10:23:29Z</dc:date>
    <item>
      <title>mkl_sparse_sp2m Issue C++</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-sparse-sp2m-Issue-C/m-p/1342585#M32414</link>
      <description>&lt;P&gt;I'm trying to perform multiplication between two&amp;nbsp;sparse matrices&amp;nbsp;&lt;SPAN style="font-family: inherit;"&gt;using&amp;nbsp;mkl_sparse_sp2m and I'm not getting the expected result.&amp;nbsp; Below is my example code showing the computed and expected result. What am I doing wrong?:&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;assert.h&amp;gt; 
#include "mkl_spblas.h"

void checkStat(const int&amp;amp; stat) {
    if(stat != SPARSE_STATUS_SUCCESS) {
        std::cout &amp;lt;&amp;lt; "Status: " &amp;lt;&amp;lt; stat &amp;lt;&amp;lt; std::endl;
        assert(false);
    }
}

void outputCsr(sparse_matrix_t&amp;amp; A) {
    MKL_INT rowsC, colsC;
    sparse_index_base_t indexing = SPARSE_INDEX_BASE_ZERO;
    MKL_INT *cols_start = NULL, *cols_end = NULL, *row_indx = NULL;
    double *values_C = NULL;
    checkStat(mkl_sparse_d_export_csr(A,
        &amp;amp;indexing,
        &amp;amp;rowsC,
        &amp;amp;colsC,
        &amp;amp;cols_start,
        &amp;amp;cols_end,
        &amp;amp;row_indx,
        &amp;amp;values_C));

    int len_row_index = cols_end[colsC - 1] - cols_start[0];
    int k = rowsC;

    std::cout &amp;lt;&amp;lt; "Rows, Cols = " &amp;lt;&amp;lt; rowsC &amp;lt;&amp;lt; ", " &amp;lt;&amp;lt; colsC &amp;lt;&amp;lt; std::endl;

    for(int i = 0; i &amp;lt; len_row_index; ++i)
        std::cout &amp;lt;&amp;lt; values_C[i] &amp;lt;&amp;lt; ", ";
    std::cout &amp;lt;&amp;lt; std::endl;

    for(int i = 0; i &amp;lt; len_row_index; ++i)
        std::cout &amp;lt;&amp;lt; row_indx[i] &amp;lt;&amp;lt; ", ";
    std::cout &amp;lt;&amp;lt; std::endl;

    for(int i = 0; i &amp;lt; k; ++i)
        std::cout &amp;lt;&amp;lt; cols_start[i] &amp;lt;&amp;lt; ", ";
    std::cout &amp;lt;&amp;lt; std::endl;

    for(int i = 0; i &amp;lt; k; ++i)
        std::cout &amp;lt;&amp;lt; cols_end[i] &amp;lt;&amp;lt; ", ";
    std::cout &amp;lt;&amp;lt; std::endl;
}

int main() {
    int m = 3;
    int k = 3;

    sparse_matrix_t A;

    /* Matrix in CRS format
    *
    * { { 0,  0,  1 } 
    *   { 0, -1,  2 } 
    *   { 1,  0,  0 } } 
    */
    double vals[] = { 1, -1, 2, 1 };
    int cols[]   = { 2, 1, 2, 0 };
    int ptrB[]  = { 0, 1, 3 };
    int ptrE[]  = { 1, 3, 4 };

    checkStat(mkl_sparse_d_create_csr(&amp;amp;A,
        SPARSE_INDEX_BASE_ZERO, // indexing (base),
        m,      // rows,
        k,      // cols,
        ptrB,    // rows_start,
        ptrE,    // rows_end,
        cols,      // col_indx,
        vals));
    std::cout &amp;lt;&amp;lt; "A" &amp;lt;&amp;lt; std::endl;
    outputCsr(A);

    matrix_descr descr;
    descr.type = SPARSE_MATRIX_TYPE_GENERAL;

    sparse_matrix_t B;

    checkStat(mkl_sparse_sp2m(
        SPARSE_OPERATION_NON_TRANSPOSE,
        descr,
        A,
        SPARSE_OPERATION_NON_TRANSPOSE,
        descr,
        A,
        SPARSE_STAGE_FULL_MULT,
        &amp;amp;B));

    std::cout &amp;lt;&amp;lt; "Result:" &amp;lt;&amp;lt; std::endl;
    outputCsr(B);

    /* Expected answer
    *
    * { { 1,  0,  0 } 
    *   { 2,  1,  -2 } 
    *   { 0,  0,  1 } } 
    * 
    *  vals: 1, 2, 1, -2
    *  cols: 0, 0, 1, 2, 2
    *  ptrB: 0, 1, 4,
    *  prtE: 1, 2, 5
    * 
    * MKL Answer
    * { {1, 0, 0}
    *   {0, 1, -2}
    *   {2, 0, 1}}
    * 
    *   vals: 1, 1, -2, 2, 1, 
    *   cols: 0, 1, 2, 0, 2, 
    *   ptrB: 0, 1, 4, 
    *   ptrE: 1, 4, 5
    */

    checkStat(mkl_sparse_destroy(A));

    return 0;
}&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 08 Dec 2021 20:32:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-sparse-sp2m-Issue-C/m-p/1342585#M32414</guid>
      <dc:creator>streamsky</dc:creator>
      <dc:date>2021-12-08T20:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: mkl_sparse_sp2m Issue C++</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-sparse-sp2m-Issue-C/m-p/1342769#M32416</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for reaching out to us.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output column/row indices for sp2m are not sorted, this is implied by the algorithm currently used.&lt;/P&gt;
&lt;P&gt;In order to sort the indices, you can call&lt;STRONG&gt; mkl_sparse_order&lt;/STRONG&gt; for the resultant matrix (here it is B) after using mkl_sparse_sp2m.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just insert the mkl_sparse_order function as below in your code&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;std::cout &amp;lt;&amp;lt; "Result:" &amp;lt;&amp;lt; std::endl;
checkStat(mkl_sparse_order (B));
outputCsr(B);&lt;/LI-CODE&gt;
&lt;P&gt;After making the above changes, recompile the code and you will get the expected results.&lt;/P&gt;
&lt;P&gt;Please do let us know if you face any issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Vidya.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 10:23:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-sparse-sp2m-Issue-C/m-p/1342769#M32416</guid>
      <dc:creator>VidyalathaB_Intel</dc:creator>
      <dc:date>2021-12-09T10:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: mkl_sparse_sp2m Issue C++</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-sparse-sp2m-Issue-C/m-p/1342824#M32420</link>
      <description>&lt;P&gt;Vidya,&lt;/P&gt;
&lt;P&gt;Thank you for the solution. &amp;nbsp;&amp;nbsp;Could you please expand upon "implied by the algorithm" and the use of &lt;STRONG class="sub_section_element_selectors"&gt;mkl_sparse_order&lt;/STRONG&gt;? &amp;nbsp;I haven't found these insights in the developer reference. &amp;nbsp;For example, does&amp;nbsp;&lt;STRONG class="sub_section_element_selectors"&gt;mkl_sparse_order&amp;nbsp;&lt;/STRONG&gt;need to be called to view a matrix in CSR format after MKL sparse matrix operations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, for anyone else reading this, the expect answer should have been:&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;vals: 1, 2, 1, -2, 1&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;cols: 0, 0, 1, 2, 2&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;ptrB: 0, 1, 4,&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;prtE: 1, 4, 5&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;David&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 09 Dec 2021 14:22:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-sparse-sp2m-Issue-C/m-p/1342824#M32420</guid>
      <dc:creator>streamsky</dc:creator>
      <dc:date>2021-12-09T14:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: mkl_sparse_sp2m Issue C++</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-sparse-sp2m-Issue-C/m-p/1343527#M32427</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We'll update the documentation of sp2m to say about potential unsortedness.&lt;/P&gt;
&lt;P&gt;If you are curious about the reasons: while oneMKL neither exposes any information about the algorithm used or makes any promises to use only one of the existing ones, a very well known Gustavson algorithm for sparse * sparse matrix multiplication naturally produces unsorted indices for the output.&lt;/P&gt;
&lt;P&gt;As a lot of functionality actually does not need the indices to be sorted, it would be an unnecessary performance penalty for these cases to do the sorting additionally within sp2m (by default, unless a special knob for sorted/unsorted output appears).&lt;/P&gt;
&lt;P&gt;Best,&lt;BR /&gt;Kirill&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 01:05:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-sparse-sp2m-Issue-C/m-p/1343527#M32427</guid>
      <dc:creator>Kirill_V_Intel</dc:creator>
      <dc:date>2021-12-13T01:05:32Z</dc:date>
    </item>
    <item>
      <title>Re:mkl_sparse_sp2m Issue C++</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-sparse-sp2m-Issue-C/m-p/1345576#M32474</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks for accepting our solution.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;As your issue is resolved we are going ahead and closing this thread. Please post a new question if you require any additional assistance from Intel as this thread will no longer be monitored.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Have a Nice Day!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vidya.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Dec 2021 04:54:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/mkl-sparse-sp2m-Issue-C/m-p/1345576#M32474</guid>
      <dc:creator>VidyalathaB_Intel</dc:creator>
      <dc:date>2021-12-21T04:54:02Z</dc:date>
    </item>
  </channel>
</rss>

