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? Thanks, Ram On Mon, Dec 5, 2016 at 9:26 PM, Barry Smith <bsm...@mcs.anl.gov> wrote: > > > On Dec 5, 2016, at 2:47 PM, K. N. Ramachandran <knra...@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