I would probably do what Barry & Jed have suggested. However, if you really want to work with blocks,<br>you can also consider what Dave has done. It is much closer to what you are asking for<br><br> <a href="http://jupiter.ethz.ch/~dmay/Research/PetscExt/index.html">http://jupiter.ethz.ch/~dmay/Research/PetscExt/index.html</a><br>
<br> Matt<br><br><div class="gmail_quote">On Mon, Jan 18, 2010 at 9:41 AM, Umut Tabak <span dir="ltr"><<a href="mailto:u.tabak@tudelft.nl">u.tabak@tudelft.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Dear all,<br>
<br>
Some time ago, I asked some questions about setting entries of a sparse matrix efficiently. I got some response from Jed Brown and Barry Smith. I can set the matrix entries of one sparse matrix very efficiently for the moment. I use MatSetValues and preallocate the array as explained in the manual for performance and set the rows in once in a loop. My actual goal was to set the entries of a matrix in blocks. Let me rephrase, say I would like to set the blocks of a matrix like<br>
1 1<br>
1 [ Kaa Kas ] or [ Kaa 0 ] does not matter.<br>
2 [ 0 Kss ] [ Ksa Kss ]<br>
<br>
Since I can read the matrices Kaa, Ksa, Kss, and their non-zeros, row and column indices of these matrices alone.<br>
<br>
I thought that to get the same efficient setting of values, I can do some kind of block selection on a 'switch' where I can allocate the nnz, and values for the rows of this big matrix and set the row and column indices with some offsets. I mean sth like if blocks are on the same global row, say 1, change nnz for those rows in that block and allocate the necessary space and set the values of this array. But I thought this should be done before me by someone else, so just wanted some advice before coding. All blocks are pretty sparse if that helps from the point of view of ideas. If I do not do this preallocation, the performance decreases, as explained in the manual, drastically(not for this case but for stand alone matrices for instance.)<br>
<br>
I appreciate any brighter ideas.<br><font color="#888888">
<br>
Umut<br>
<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener<br>