[petsc-users] inserting into sparse matricies

Matthew Knepley knepley at gmail.com
Fri Mar 26 10:25:34 CDT 2010


On Fri, Mar 26, 2010 at 9:18 AM, John-Michael Fischer <fischej at umich.edu>wrote:

> I have a vector of values I want to insert into a sparse matrix as a row.
>  My vector contains non-zero values at their proper positions in the row and
> zero's elsewhere.  If I MatSetValues into a Mat setup in a sparse form, will
> PETSC automatically see the zero's and not insert them while working out the
> proper indecies of the non-zero elements?
>
> Is there another calling sequence that lets me do this without calling
> MatSetValue for each non-zero entry since the non-zero entries are not
> contiguous in the row?
>
> Alternatively, I was thinking I could assemble a vector with the indecies
> of the non-zero elements, then use that in the call to MatSetValues with a
> row vector of non-zero values only - but I wanted to ask first since this
> seems like a common usage pattern for PETSC sparse mat's.
>

This is not very common, since Mats are usually very sparse, looking at
every value would be
incredibly time consuming. I recommend compressing the row down to the
nonzeros, and then
calling MatSetValues(). There is a flag you can set,
MAT_IGNORE_ZERO_ENTRIES,
that will ignore zeros, but this would not be my first choice.

   Matt


> Thanks,
> John-Michael




-- 
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/20100326/ad3fd78f/attachment.htm>


More information about the petsc-users mailing list