Ben, You'll want to use MatZeroRows() (even if it is just one row) Also take a look at MatSetOption() and the option MAT_KEEP_ZEROED_ROWS.
Barry On Wed, 20 Jun 2007, Ben Tay wrote: > Hi, > > I tried to do it in 2 ways: > > A: > > 1.Do initial sweep: > > do j=1,size_y > > do i=1,size_x > > matsetvalue .... > > end do > > end do" > > 2.matssemblybegin/end > > 3 do a loop using matzerorows to zeros the particular rows > > 4. do loop and use matsetvalues to insert values into those rows which I had > zeroed previously > > 5 matssemblybegin/end > > 6 solve > > > > B: > > 1. Same as A > > 2 use matsetvalues to put zeros into those location where I earlier insert > in the 1st full i,j sweep > 3. insert correct value using matsetvalues > > 4. finally matassemblybegin/end - just once. > > 5. solve > > l realised that B is about 3 times faster than A. May I know why this is > so? In A, I only call matssemblybegin/end once more. Is it so serious to the > performance? > > > > Thanks > > On 6/11/07, Barry Smith <bsmith at mcs.anl.gov> wrote: > > > > > > > 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 > > > > > > > > > > > > > > > > > > > > >