<?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 So, this is a sort of tricky in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Block-sparse-matrix-with-sparse-matrix/m-p/1179201#M29199</link>
    <description>&lt;P&gt;So, this is a sort of a tricky case to do with existing functionality,&amp;nbsp; you could probably use the mkl_sparse_?_add functionality, but that would require you to call it 3 times and adjust some arrays as you go with their offsets.&amp;nbsp; I would probably instead write if from scratch.&amp;nbsp; Maybe something like the following:&lt;/P&gt;&lt;P&gt;Two steps to do full computation.&amp;nbsp; I will assume you are using CSR format to represent the matrices.&amp;nbsp;For this to make sense, M and K must have the same number of rows, but columns can be different, so suppose M is nxm&amp;nbsp; and K is nxk., then your new sparse matrix has global dimensions (nrows=2n) x (ncols=m+k).&amp;nbsp; Let M be represented by Mrowptr, Mcolumns and Mvalues arrays, and K be represented by Krowptr, Kcolumns, Kvalues arrays.&amp;nbsp; Finally let rowptr, columns and values arrays be the CSR representation for the new A matrix.&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; Construct new rowptr array and initialize memory for new matrix. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Let us consider the number of sparse elements of first row (same as the m+1 row).&amp;nbsp; We will use 0 based (c-style) indexing in our arrays.&amp;nbsp; &amp;nbsp; The the first row of new matrix has Mrowptr[1]-Mrowptr[0] + Krowptr[1]-Krowptr[0] nonzero elements.&amp;nbsp;&amp;nbsp; then rowptr[0] = 0&amp;nbsp; and rowptr[1] =&amp;nbsp;Mrowptr[1]-Mrowptr[0] + Krowptr[1]-Krowptr[0]&lt;/P&gt;&lt;P&gt;You can go through and calculate new row lengths independently of each other.&amp;nbsp; So if using parallelism, this is a simple parallel for loop (OMP or TBB) otherwise it is just a for loop.&amp;nbsp; I would recommend filling in each value with the number of nonzero elements on that row.&amp;nbsp; Then you do a second pass to calculate the prefix sum (partial sums increasing up to the end) of this rowptr array.&amp;nbsp; Once this is done, you know how big the columns arrays need to be and where each row can start. Now allocate memory for the new columns and values arrays.&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; Now you can fill in proper values of the column and values arrays.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again this can be done independently on each row so a simple (parallel) for loop will handle the computations. For columns of M being copied, there are no offsets, it can be copied as is, but for the columns of K, you need to offset (read this as add) by m (the number of columns in M) to shift it to the right blocks.&amp;nbsp; The values for each row can be copied and scaled as desired to match your 4 blocks,&amp;nbsp; one row at a time...&lt;/P&gt;&lt;P&gt;I hope that was detailed enough for you to see how to do it.&amp;nbsp; Best of luck!&lt;/P&gt;&lt;P&gt;Spencer&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Dec 2018 19:01:59 GMT</pubDate>
    <dc:creator>Spencer_P_Intel</dc:creator>
    <dc:date>2018-12-20T19:01:59Z</dc:date>
    <item>
      <title>Block sparse matrix with sparse matrix</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Block-sparse-matrix-with-sparse-matrix/m-p/1179199#M29197</link>
      <description>&lt;P&gt;I have a sparse matrix M, and a sparse matrix K,&amp;nbsp; both of the sparse matrices&amp;nbsp;obtain the same non-zeros location, how to form a sparse matrix with following format:&lt;/P&gt;&lt;P&gt;A= [ M,&amp;nbsp; 0.2K;&amp;nbsp; 0.1M, 0.1K];&lt;/P&gt;&lt;P&gt;This was used to solve linear equation with Ax = b.&lt;/P&gt;&lt;P&gt;Thanks a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Dec 2018 13:06:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Block-sparse-matrix-with-sparse-matrix/m-p/1179199#M29197</guid>
      <dc:creator>Li__Yapeng</dc:creator>
      <dc:date>2018-12-19T13:06:02Z</dc:date>
    </item>
    <item>
      <title>Yapeng,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Block-sparse-matrix-with-sparse-matrix/m-p/1179200#M29198</link>
      <description>&lt;P&gt;Yapeng,&lt;/P&gt;&lt;P&gt;Please explain "&lt;EM&gt;obtain the same non-zeros location&lt;/EM&gt;". Obtain them from where? Or do you mean the matrices have non-zero values in the same row,column positions?&lt;/P&gt;&lt;P&gt;Also, please identify or explain&amp;nbsp;the format you are using.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;A= [ M,&amp;nbsp; 0.2K;&amp;nbsp; 0.1M, 0.1K];&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Pamela&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 18:29:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Block-sparse-matrix-with-sparse-matrix/m-p/1179200#M29198</guid>
      <dc:creator>Pamela_H_Intel</dc:creator>
      <dc:date>2018-12-20T18:29:21Z</dc:date>
    </item>
    <item>
      <title>So, this is a sort of tricky</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Block-sparse-matrix-with-sparse-matrix/m-p/1179201#M29199</link>
      <description>&lt;P&gt;So, this is a sort of a tricky case to do with existing functionality,&amp;nbsp; you could probably use the mkl_sparse_?_add functionality, but that would require you to call it 3 times and adjust some arrays as you go with their offsets.&amp;nbsp; I would probably instead write if from scratch.&amp;nbsp; Maybe something like the following:&lt;/P&gt;&lt;P&gt;Two steps to do full computation.&amp;nbsp; I will assume you are using CSR format to represent the matrices.&amp;nbsp;For this to make sense, M and K must have the same number of rows, but columns can be different, so suppose M is nxm&amp;nbsp; and K is nxk., then your new sparse matrix has global dimensions (nrows=2n) x (ncols=m+k).&amp;nbsp; Let M be represented by Mrowptr, Mcolumns and Mvalues arrays, and K be represented by Krowptr, Kcolumns, Kvalues arrays.&amp;nbsp; Finally let rowptr, columns and values arrays be the CSR representation for the new A matrix.&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; Construct new rowptr array and initialize memory for new matrix. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Let us consider the number of sparse elements of first row (same as the m+1 row).&amp;nbsp; We will use 0 based (c-style) indexing in our arrays.&amp;nbsp; &amp;nbsp; The the first row of new matrix has Mrowptr[1]-Mrowptr[0] + Krowptr[1]-Krowptr[0] nonzero elements.&amp;nbsp;&amp;nbsp; then rowptr[0] = 0&amp;nbsp; and rowptr[1] =&amp;nbsp;Mrowptr[1]-Mrowptr[0] + Krowptr[1]-Krowptr[0]&lt;/P&gt;&lt;P&gt;You can go through and calculate new row lengths independently of each other.&amp;nbsp; So if using parallelism, this is a simple parallel for loop (OMP or TBB) otherwise it is just a for loop.&amp;nbsp; I would recommend filling in each value with the number of nonzero elements on that row.&amp;nbsp; Then you do a second pass to calculate the prefix sum (partial sums increasing up to the end) of this rowptr array.&amp;nbsp; Once this is done, you know how big the columns arrays need to be and where each row can start. Now allocate memory for the new columns and values arrays.&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; Now you can fill in proper values of the column and values arrays.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again this can be done independently on each row so a simple (parallel) for loop will handle the computations. For columns of M being copied, there are no offsets, it can be copied as is, but for the columns of K, you need to offset (read this as add) by m (the number of columns in M) to shift it to the right blocks.&amp;nbsp; The values for each row can be copied and scaled as desired to match your 4 blocks,&amp;nbsp; one row at a time...&lt;/P&gt;&lt;P&gt;I hope that was detailed enough for you to see how to do it.&amp;nbsp; Best of luck!&lt;/P&gt;&lt;P&gt;Spencer&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 19:01:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Block-sparse-matrix-with-sparse-matrix/m-p/1179201#M29199</guid>
      <dc:creator>Spencer_P_Intel</dc:creator>
      <dc:date>2018-12-20T19:01:59Z</dc:date>
    </item>
  </channel>
</rss>

