Hi,<br>I would also greatly appreciate reading this code! Perhaps, other users also would!<br>Could you please post it on this mailing list or somewhere on PETSc's web site?<br>Thanks,<br>Nicolas<br><br><div class="gmail_quote">
2009/12/19 Douglas Arnold <span dir="ltr"><<a href="mailto:arnold@umn.edu">arnold@umn.edu</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
For me, two copies of the matrix is not a problem. That is what I was looking for but didn't find, something that efficiently copied a sparse matrix into a bigger sparse matrix. I would appreciate<br>
receiving the code for the sequential case, if it is not much<br>
bother for you.<br>
<br>
Thanks. -- Doug<div><div></div><div class="h5"><br>
<br>
On 12/18/2009 06:12 PM, Barry Smith wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
The issue is that the data structures that PETSc uses to store the<br>
sparse matrices are not designed to allow changing the matrix size, thus<br>
if you have the matrix A as a PETSc sparse matrix creating B means<br>
copying the entire matrix, thus two copies of the matrix, more memory<br>
usage. Now if memory is not an issue for you, the copying can be done<br>
efficiently order nz work. I can send you code for the sequential case.<br>
<br>
If you don't want two copies of the matrix for memory reasons, could you<br>
"lie" to the part of the code that generates A and have it create the A<br>
with an extra row and column that it simply does not use? So in the<br>
MatSetSizes() you just set it 1 larger then it is. Then call the<br>
MatSetValues() to fill up A then call the MatSetValues() to put in the v<br>
and c part without calling MatAssemblyBegin/End() in between and you<br>
will have an efficient code in both time and memory usage.<br>
<br>
Barry<br>
<br>
On Dec 18, 2009, at 5:59 PM, Douglas Arnold wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Anirban Chatterjee asked how to assemble an (n+1)x(n+1) sparse matrix<br>
<br>
B = [A v;<br>
v^T c]<br>
<br>
from an nxn sparse matrix A, a vector v, and a scalar c. Matt<br>
Knepley and Barry Smith advised against it.<br>
<br>
I have pretty much the same problem and I want to make sure I<br>
understand the situation. In my case, the matrix A comes to me<br>
from another application that I would rather not fiddle with.<br>
The rank of A is n-1 and v is a vector in its nullspace, c=0. I would<br>
like to solve a system with the matrix B by a direct solver, and<br>
so I think I need to assemble it. Do I understand correctly that<br>
there is no efficient way to do this in PETSc? Even in a sequential<br>
computation?<br>
<br>
-- Doug<br>
<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Where will the "new" row live? On the last process, why that one?<br>
<br>
Does the matrix A have to be completely assembled before the v is<br>
computed? Or can the entries of A be computed at the same time as the v?<br>
<br>
PETSc doesn't have code to efficiently dynamically change the size<br>
of a matrix. Thus generating a new matrix from a given sparse matrix<br>
plus a new row requires a complete copy of the starting matrix into<br>
the new matrix data structure. If you assemble the entire matrix<br>
together without first generating the smaller matrix A then it is<br>
easy; just generate the preallocation structure of A with the one<br>
additional row/column information and call MatSetValues() to put in<br>
the parts of A and the parts of v.<br>
<br>
Barry<br>
<br>
On Dec 8, 2009, at 4:05 PM, Anirban Chatterjee wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
I have an nxn matrix A, a column vector v and a scalar c. I want to<br>
assemble a matrix B as follows,<br>
B = [A v;<br>
v^T c]<br>
Can someone tell me the easiest and most efficient way to do this.<br>
<br>
--Anirban<br>
</blockquote></blockquote></blockquote>
<br>
</blockquote>
</div></div></blockquote></div><br>