<?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:[C Interface] Updating the values of a CSC matrix in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/C-Interface-Updating-the-values-of-a-CSC-matrix/m-p/1689535#M37144</link>
    <description>&lt;P&gt;With no response from you, this issue will no longer be tracked by Intel.&lt;/P&gt;&lt;P&gt;If you have further queries, please feel free to post them in the forum.&lt;/P&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 13 May 2025 11:34:58 GMT</pubDate>
    <dc:creator>Aleksandra_K</dc:creator>
    <dc:date>2025-05-13T11:34:58Z</dc:date>
    <item>
      <title>[C Interface] Updating the values of a CSC matrix</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/C-Interface-Updating-the-values-of-a-CSC-matrix/m-p/1684566#M37082</link>
      <description>&lt;P&gt;&amp;nbsp;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for my master's thesis I am implementing a simulation routine, which involves for each iteration:&lt;/P&gt;&lt;P&gt;a) matrix-matrix multiplication of a diagonal matrix with a sparse matrix (mkl_sparse_sp2m)&lt;/P&gt;&lt;P&gt;b) Some custom accumulation results from a) yielding a dense vector&lt;/P&gt;&lt;P&gt;c) sparse matrix-vector multiplication with the vector from b). (mkl_sparse_d_mv)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to minimize overhead in this critical portion of the code. See below the message for the code snippets in question.&lt;/P&gt;&lt;P&gt;After some trial and error I have two questions, which the docs could not resolve for me:&lt;/P&gt;&lt;P&gt;1.&lt;/P&gt;&lt;P&gt;The Diagonal matrix xuDiag from a) stays structurally constant. For every iteration, I just want to update&amp;nbsp; the main diagonal to the result of c). I was hoping to just overwrite the pointer to the values (given at initial creation to mkl_sparse_d_create_csc). This does not seem to have an effect. Since mkl_sparse_?_update_values only supports bsr, is my only option to recreate the whole matrix for every iteration?&lt;/P&gt;&lt;P&gt;I would very much like to avoid this kind of overhead and just write to the internal value array directly or at least have a way of updating only the values without recreating the whole structure for every iteration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Edit:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;After browsing through more related forum Posts I read Spencer_P_Intel's &lt;A href="https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Releasing-Sparse-Matrix-Handle-and-Arrays/m-p/1300038/highlight/true#M31772" target="_blank" rel="noopener"&gt;Post&lt;/A&gt;, which touches on this topic I believe. This strengthens my first suspicion, that my naive approach of changing the pointer "below the libraries feet" is ill-concieved.&lt;/P&gt;&lt;P&gt;This does leave me with the question, what possibilties do I have for editing values of matrices?&lt;/P&gt;&lt;P&gt;I rely on CSC (CSR in a pinch) for efficient intermediary calculations, so i can only&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;recreate the diagonal matrix for every iteration&lt;/LI&gt;&lt;LI&gt;loop through every nnz one by one via mkl_sparse_d_set_value&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;?&lt;/P&gt;&lt;P&gt;1.5&lt;/P&gt;&lt;P&gt;After reading through Spencer's above mentioned post, there is another question that is on my mind the whole way through learning my way around this library:&lt;/P&gt;&lt;P&gt;Where would I go and learn about these implicit (or explicit) agreements that are mentioned here? I see that in the C++ docs, there seem to be more hints about this I don't expect this information to translate to C, at least not fully?&lt;/P&gt;&lt;P&gt;The same goes for informations like &lt;A href="https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/question-about-sparse-routines-matrix-formats-support/m-p/1675554/highlight/true#M36998" target="_blank" rel="noopener"&gt;this&lt;/A&gt;. It's very useful to know that CSR is the preferred format to use, but how could I have known this prior to seeing the limitations on the seperate function or this forum?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to stress:This is not meant as criticism in any way - on the contrary I a very grateful for the great software and maintenance provided by this team. All the more motivation for me ( and maybe future readers) to find that info ourselves and save time for everyone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Reading through the documentation, I noticed that the interfaces for C and C++ show noticable differences. For C the Inspector-Executor matrix-matrix multiplication for example only supports the SPARSE_MATRIX_TYPE_GENERAL, while the C++ documentation indicates no such restriction.&lt;/P&gt;&lt;P&gt;Is there a functionally a difference between the C and C++ interfaces, and would one or the other be more advisable in terms of performance regarding sparse inspector-executor operations?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am very grateful for any input and hope you have a great day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EnricoU&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it would be of any help, I would gladly attach the sourcecode.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;sparse_status_t xuDiag_status = mkl_sparse_d_create_csc(
        &amp;amp;xuDiag,
        SPARSE_INDEX_BASE_ONE,
        U_m, U_m,       // !! U_m x U_m
        nnz_rows,
        (nnz_rows + 1), 
        cols,       
        xu
    );

sparse_status_t Uxu_status = mkl_sparse_sp2m(
        SPARSE_OPERATION_NON_TRANSPOSE,
        descA,
        xuDiag,
        SPARSE_OPERATION_NON_TRANSPOSE,
        descB,
        U,
        SPARSE_STAGE_FULL_MULT,
        &amp;amp;Uxu
);

 sparse_status_t expStatus = mkl_sparse_d_export_csc(
        Uxu,
        &amp;amp;index_base,
        &amp;amp;Uxu_rows,
        &amp;amp;Uxu_cols,
        &amp;amp;Uxu_rows_start,
        &amp;amp;Uxu_rows_end,
        &amp;amp;Uxu_col_inds,
        &amp;amp;Uxu_vals
);

/* Some calculations on Uxu_vals */

const int t_num = 10; 
double **x_result = (double**) mkl_malloc(t_num * sizeof(double*),64);
for (size_t i = 0; i &amp;lt; 10; i++)
{
    x_result[i] = (double*) mkl_malloc(Phi_m * sizeof(double),64);
}

sparse_status_t finalStatus = mkl_sparse_d_mv(
    SPARSE_OPERATION_NON_TRANSPOSE,
    1.0,
    Phi,
    descA,
    Uxucum,
    0.0,        // 1.0 would include the values already being there
    x_result[0]
);

xu = x_result[0];   // raw pointer tomfoolery
vdPackI(
    URef_n,         // number of elements
    URef_vals + 1,  // source
    URef_m,         // step size source. CSC 
    (xu + XRef_n)   // dest  with offset, since u has to come "after" x
);
/* This operation I would like to avoid, since this portion of the code will the most often */

xuDiag_status = mkl_sparse_d_create_csc(
        &amp;amp;xuDiag,
        SPARSE_INDEX_BASE_ONE,
        U_m, U_m,       // !! U_m x U_m
        nnz_rows,
        (nnz_rows + 1), 
        cols,       // For diagonal matrices, rows_start == rows_end  == cols
        xu
);
/* This operation does not work, without re-creating xuDiag as above
*  Internal representation of xuDiag seems to be unimpressed by the reassignment of xu   
*/
Uxu_status = mkl_sparse_sp2m(
    SPARSE_OPERATION_NON_TRANSPOSE,
    descA,
    xuDiag,
    SPARSE_OPERATION_NON_TRANSPOSE,
    descB,
    U,
    SPARSE_STAGE_FINALIZE_MULT, // Only recompute the values, reuse everything else. 
    &amp;amp;Uxu
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Apr 2025 11:59:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/C-Interface-Updating-the-values-of-a-CSC-matrix/m-p/1684566#M37082</guid>
      <dc:creator>EnricoU</dc:creator>
      <dc:date>2025-04-22T11:59:31Z</dc:date>
    </item>
    <item>
      <title>Re:[C Interface] Updating the values of a CSC matrix</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/C-Interface-Updating-the-values-of-a-CSC-matrix/m-p/1686657#M37102</link>
      <description>&lt;P&gt;Hi Enrico,&lt;/P&gt;&lt;P&gt;Thank you for posting the issue. Please share the code, and I'll look into it more deeply&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Apr 2025 10:34:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/C-Interface-Updating-the-values-of-a-CSC-matrix/m-p/1686657#M37102</guid>
      <dc:creator>Aleksandra_K</dc:creator>
      <dc:date>2025-04-30T10:34:18Z</dc:date>
    </item>
    <item>
      <title>Re:[C Interface] Updating the values of a CSC matrix</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/C-Interface-Updating-the-values-of-a-CSC-matrix/m-p/1687872#M37116</link>
      <description>&lt;P&gt;Hi, do you have any updates regarding the code?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 06 May 2025 15:47:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/C-Interface-Updating-the-values-of-a-CSC-matrix/m-p/1687872#M37116</guid>
      <dc:creator>Aleksandra_K</dc:creator>
      <dc:date>2025-05-06T15:47:38Z</dc:date>
    </item>
    <item>
      <title>Re:[C Interface] Updating the values of a CSC matrix</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/C-Interface-Updating-the-values-of-a-CSC-matrix/m-p/1689535#M37144</link>
      <description>&lt;P&gt;With no response from you, this issue will no longer be tracked by Intel.&lt;/P&gt;&lt;P&gt;If you have further queries, please feel free to post them in the forum.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 13 May 2025 11:34:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/C-Interface-Updating-the-values-of-a-CSC-matrix/m-p/1689535#M37144</guid>
      <dc:creator>Aleksandra_K</dc:creator>
      <dc:date>2025-05-13T11:34:58Z</dc:date>
    </item>
  </channel>
</rss>

