On Thu, Mar 1, 2012 at 5:03 PM, Vaclav Hapla <span dir="ltr"><<a href="mailto:vaclav.hapla@vsb.cz">vaclav.hapla@vsb.cz</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dear PETSc team,<br>
why I am not able to do this:<br>
<br>
...<br>
MatCreate(PETSC_COMM_SELF, &Kreg);<br>
MatSetSizes(Kreg,m,n,m,n);<br>
MatSetType(Kreg, MATSEQAIJ);<br>
MatSeqAIJSetPreallocation(<u></u>Kreg,0,nnz);<br>
MatAssemblyBegin(Kreg, MAT_FINAL_ASSEMBLY);<br>
MatAssemblyEnd(   Kreg, MAT_FINAL_ASSEMBLY);<br>
PetscFree(nnz);<br>
{<br>
    PetscInt nz_Kreg;<br>
    MatGetRow(Kreg, 0, &nz_Kreg, PETSC_IGNORE, PETSC_IGNORE);<br>
    PetscPrintf(PETSC_COMM_SELF, "nnz %d  Kreg %d\n", nnz[0], nz_Kreg);  // prints nnz 11  Kreg 0 !!!<br>
}<br>
MatCopy(K_loc, Kreg, DIFFERENT_NONZERO_PATTERN); //fails: New nonzero at (0,0) caused a malloc!<br></blockquote><div><br></div><div>I think you want</div><div><br></div><div><a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatDuplicate.html">http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatDuplicate.html</a></div>
<div><br></div><div>which does it in one line.</div><div><br></div><div>   Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
PETSc complains about new nonzero - not surprisingly because MatAssemblyBegin/End filters zeros as I understand.<br>
But when I comment out MatAssemblyBegin/End, MatCopy complains that it is only for assembled matrices.<br>
<br>
I think that to call MatSetValues on all allocated nonzeros just to make them survive MatAssemblyBegin/End or to replace MatCopy call by loop over raw array is both quite awkward.<br>
Maybe one should be able to turn the filter in MatAssemblyBegin/End off. Or is there any other way out?<br>
<br>
BTW, what I need is to make a copy Kreg of given matrix K_loc but with few additional preallocated positions which are filled later. Is there some other convenient solution?<br>
<br>
Cheers,<br>
Vaclav Hapla<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <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>