[petsc-users] Hash Function for PETSc Sparse Matrices

Matthew Knepley knepley at gmail.com
Tue Dec 6 09:39:08 CST 2016


On Tue, Dec 6, 2016 at 9:31 AM, K. N. Ramachandran <knram06 at gmail.com>
wrote:

> Hello Jed, Barry,
>
> Thanks for the inputs. Yes, I am trying to spot duplicate sparse Matrices
> basically and avoid storing if possible. MatGetNonzeroState() seems useful
> here and I'll take a closer look.
>
> I couldn't find the PetscObjectGetState() though from the available API (
> http://www.mcs.anl.gov/petsc/petsc-current/docs/
> manualpages/singleindex.html). Was there another closely related function
> I should take a look at?
>

http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscObjectStateGet.html

  Matt


> Thanks,
> Ram
>
>
>
> On Mon, Dec 5, 2016 at 9:26 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>
>>
>> > On Dec 5, 2016, at 2:47 PM, K. N. Ramachandran <knram06 at gmail.com>
>> wrote:
>> >
>> > Hello PETSc-Users,
>> >
>> > I am working on an application where we capture the A matrix in a
>> linear system Ax=b, which is solved using Petsc. Let us also say that the
>> matrix A can change after a few iterations. We want to capture only the
>> changed matrices and simply avoid the duplicate ones.
>> >
>> > I was considering using (or defining) a Set-like data structure that
>> stores only the Mat objects which have changed entries. So a hash function
>> that can operate on a sparse matrix would be pretty useful here.
>> >
>> > This seems like a common enough use case and I was wondering if anyone
>> can give their inputs on defining a hash function that can operate on
>> sparse matrices. One such link I had found online is:
>> > http://stackoverflow.com/questions/10638373/suitable-hash-
>> function-for-matrix-sparsity-pattern
>> >
>> > Any thoughts or comments would be great here.
>>
>> PETSc automatically tracks changes in the numerical values and sparsity
>> pattern of its matrices. So, for example, if you call MatSetValues() and
>> MatAssemblyBegin/End() then the KSP associated with the Mat "knows" the
>> matrix has changed. Similarly if the sparsity pattern changes then
>> preconditioners that depend on the sparsity pattern, such as ILU, take the
>> change into account when they rebuild the preconditioner. You can inquire a
>> PETSc matrix for its current state or nonzero pattern state and compare
>> with saved previous state to see if it has changed us PetscObjectGetState()
>> for numerical changes and MatGetNonzeroState() for nonzero structure
>> changes.
>>
>> I don't know if this is related to your inquiry or not.
>>
>>   Barry
>>
>> >
>> >
>> > Thanking You,
>> > Ramachandran
>>
>>
>
>
> --
> K.N.Ramachandran
> Ph: 814-441-4279 <(814)%20441-4279>
>



-- 
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20161206/123d7d7c/attachment.html>


More information about the petsc-users mailing list