This is what I used before for a long time until now when I updated PETSc and it started to complain "New nonzero caused a malloc!" when I wanted to add some new nonzero outside of the original nnz-pattern. MatDuplicate is always retaining the pattern, isn't it? Vaclav
On 03/02/2012 12:06 AM, Matthew Knepley wrote: > On Thu, Mar 1, 2012 at 5:03 PM, Vaclav Hapla <vaclav.hapla at vsb.cz > <mailto:vaclav.hapla at vsb.cz>> wrote: > > Dear PETSc team, > why I am not able to do this: > > ... > MatCreate(PETSC_COMM_SELF, &Kreg); > MatSetSizes(Kreg,m,n,m,n); > MatSetType(Kreg, MATSEQAIJ); > MatSeqAIJSetPreallocation(Kreg,0,nnz); > MatAssemblyBegin(Kreg, MAT_FINAL_ASSEMBLY); > MatAssemblyEnd( Kreg, MAT_FINAL_ASSEMBLY); > PetscFree(nnz); > { > PetscInt nz_Kreg; > MatGetRow(Kreg, 0, &nz_Kreg, PETSC_IGNORE, PETSC_IGNORE); > PetscPrintf(PETSC_COMM_SELF, "nnz %d Kreg %d\n", nnz[0], > nz_Kreg); // prints nnz 11 Kreg 0 !!! > } > MatCopy(K_loc, Kreg, DIFFERENT_NONZERO_PATTERN); //fails: New > nonzero at (0,0) caused a malloc! > > > I think you want > > http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatDuplicate.html > > which does it in one line. > > Matt > > > PETSc complains about new nonzero - not surprisingly because > MatAssemblyBegin/End filters zeros as I understand. > But when I comment out MatAssemblyBegin/End, MatCopy complains > that it is only for assembled matrices. > > 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. > Maybe one should be able to turn the filter in > MatAssemblyBegin/End off. Or is there any other way out? > > 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? > > Cheers, > Vaclav Hapla > > > > > -- > What most experimenters take for granted before they begin their > experiments is infinitely more interesting than any results to which > their experiments lead. > -- Norbert Wiener -- Vaclav Hapla Research assistant SPOMECH project <http://spomech.vsb.cz/> Centre of Excellence IT4Innovations <http://www.it4i.eu/> tel.: (+420) 59 732 6291 VSB-Technical University of Ostrava 17.listopadu 15/2172 708 33 Ostrava-Poruba Czech Republic -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20120302/a072d1b8/attachment.html>
