How to zero all values on a particular row?
Barry Smith
bsmith at mcs.anl.gov
Sun Jun 10 19:52:49 CDT 2007
On Mon, 11 Jun 2007, Ben Tay wrote:
> Thanks Barry,
>
> I managed to get it working. I realise that I had to call
> matssemblybegin/end each time after I zero a particular row. I also tried
> MatSetOption(mat,MAT_KEEP_ZEROED_ROWS) as what you 've suggested.
>
> So do I have to callMatSetOption(mat,MAT_KEEP_ZEROED_ROWS) everytime just
> before I need to zero it or just once ie after the 1st matassemblybegin/end?
Call it once when the matrix is created is fine.
>
> Calling matassemblybegin/end each time before matzerorows gives me the
> impression that it is very inefficient. Is that so?
Yes, if you do this a bunch of imes
>
> In that case, I wonder if it is better for me to :
>
> 1 use matsetvalues to put zeros into those location where I earlier insert
> in the 1st full i,j sweep
> 2. insert correct value using matsetvalues
> 3. finally matassemblybegin/end - just once.
You can do this
>
> Lastly, is MatZeroRowsIS exactly the same as matzerorows, except that it is
> meant for just 1 row instead of consecutive no. of rows?
They are the same but one takes an array of integers while the other
takes an IS. Neither require "consecutive no. of rows" you can zero
whatever rows you want together.
Barry
>
> Thanks again
>
>
> On 6/11/07, Barry Smith <bsmith at mcs.anl.gov> wrote:
> >
> >
> >
> > On Sun, 10 Jun 2007, Ben Tay wrote:
> >
> > > Hi,
> > >
> > > I need to insert values into a matrix and then solve this poisson eqn as
> > > part of my cfd code. For efficiency sake, I simply use
> > >
> > > "do j=1,size_y
> > >
> > > do i=1,size_x
> > >
> > > matsetvalue ....
> > >
> > > end do
> > >
> > > end do"
> > >
> > > to insert values into all the cells
> > >
> > > Then for specific cells, I need to enter some other values. In other
> > words,
> > > for specific rows of the matrix, I need to zero the whole row and insert
> > new
> > > values. How can I do that?
> > >
> > > I tried to use MatZeroRows but it says it's not for unassembled matrix.
> > But
> > > I need to zero the particular row, insert values, and then finally
> > assembly
> > > it. Is there a command to do this?
> >
> > matassemblybegin/end
> > matzerorows
> > matsetvalues, matsetvalues, matsetvalue
> > matssemblybegin/end
> >
> > For improved efficiency you will want to call
> > MatSetOption(mat,MAT_KEEP_ZEROED_ROWS); before the matzerorows()
> >
> > >
> > > Thanks
> > >
> >
> >
>
More information about the petsc-users
mailing list