[petsc-dev] MatSetValues with v=0
Eric Chamberland
Eric.Chamberland at giref.ulaval.ca
Wed Apr 16 09:00:05 CDT 2014
On 04/16/2014 09:44 AM, Jed Brown wrote:
> 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?
Yes this can be ok.
I have a new question now : what would be the fastest way to do the
first assembly: with INSERT_VALUES or ADD_VALUES? Right now we are
doing ADD_VALUES but I imagine it have to hold all the "0" which will be
"added" later... maybe "INSERT_VALUES" will forget about overlapping
values??... Anyway, the code I am rewriting now will hold all the
non-zeros for each "block" of similar lines... so I don't have
overlapping values... in sequential... but in parallel I think I will
have some... Anyway, any pros/cons between INSERT_VALUES or ADD_VALUES
for this first assembly?
Thanks,
Eric
More information about the petsc-dev
mailing list