[petsc-dev] MatSetValues with v=0

Jed Brown jed at jedbrown.org
Wed Apr 16 08:44:02 CDT 2014


Eric Chamberland <Eric.Chamberland at giref.ulaval.ca> writes:
> I was writing (new) code which do the firsts MatSetValues after the 
> MatXAIJSetPreallocation.  We have to do this because the "real" 
> non-zeros will be added later by a mix of ADD_VALUES and 
> INSERT_VALUES... which would prevent us to "lock" the matrix 
> (MatSetOption(aMatricePETSc, MAT_NEW_NONZERO_LOCATION_ERR, PETSC_TRUE) 
> because this option must be passed after the first MatAssemblyEnd()... 
> but all the non-zeros are "triggered" only after this "mixed" assembly...
>
> In other words, we have to do a "fake" assembly with all "0" to cover 
> all non-zeros that will be in fact added later... So we have to create 
> many "fake" elementary matrices to pass for assembly... that is why 
> Patrick was asking if the feature was supported... It would save us from 
> creating the fake matrices...  Or maybe there is a better solution?...

Just create one large-enough buffer containing all zeros.  For example,

  PetscScalar *values;
  PetscCalloc1(1000,&values);

  for (...) {
    MatSetValues(...,values,INSERT_VALUES);
  }
  PetscFree(values);

Is this okay?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20140416/6f7eb179/attachment.sig>


More information about the petsc-dev mailing list