<div>Hi,</div>
<div> </div>
<div>I tried to do it in 2 ways: </div>
<div> </div>
<div>A:</div>
<div> </div>
<div>1.Do initial sweep:</div>
<div> </div>
<div>do j=1,size_y
<p> do i=1,size_x</p>
<p> matsetvalue ....</p>
<p> end do</p>
<p>end do"</p>
<p>2.<font color="#550055">matssemblybegin/end </font></p>
<p><span class="gmail_quote">3 do a loop using <font color="#550055">matzerorows </font>to zeros the particular rows</span></p>
<p><span class="gmail_quote">4. do loop and use <font color="#550055">matsetvalues</font> to insert values into those rows which I had zeroed previously</span></p>
<p><span class="gmail_quote">5 <font color="#550055">matssemblybegin/end </font></span></p>
<p><span class="gmail_quote">6 solve</span></p>
<p><span class="gmail_quote"></span> </p>
<p><span class="gmail_quote">B:</span></p>
<p><span class="gmail_quote">1. Same as A</span></p>
<p><span class="gmail_quote">2 use matsetvalues to put zeros into those location where I earlier insert in the 1st full i,j sweep</span></p>
<div>3. insert correct value using matsetvalues</div>
<div> </div>
<div>4. finally matassemblybegin/end - just once.</div>
<div> </div>
<div>5. solve</div>
<p><span class="gmail_quote">l realised that B is about 3 times faster than A. May I know why this is so? In A, I only call <font color="#550055">matssemblybegin/end </font>once more. Is it so serious to the performance?
</span></p>
<p><span class="gmail_quote"></span> </p>
<p><span class="gmail_quote">Thanks</span></p></div>
<div><span class="gmail_quote"></span> </div>
<div><span class="gmail_quote">On 6/11/07, <b class="gmail_sendername">Barry Smith</b> <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:</span></div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><br><br>On Mon, 11 Jun 2007, Ben Tay wrote:<br><br>> Thanks Barry,<br>><br>> I managed to get it working. I realise that I had to call
<br>> matssemblybegin/end each time after I zero a particular row. I also tried<br>> MatSetOption(mat,MAT_KEEP_ZEROED_ROWS) as what you 've suggested.<br>><br>> So do I have to callMatSetOption(mat,MAT_KEEP_ZEROED_ROWS) everytime just
<br>> before I need to zero it or just once ie after the 1st matassemblybegin/end?<br><br>Call it once when the matrix is created is fine.<br>><br>> Calling matassemblybegin/end each time before matzerorows gives me the
<br>> impression that it is very inefficient. Is that so?<br><br>Yes, if you do this a bunch of imes<br><br>><br>> In that case, I wonder if it is better for me to :<br>><br>> 1 use matsetvalues to put zeros into those location where I earlier insert
<br>> in the 1st full i,j sweep<br>> 2. insert correct value using matsetvalues<br>> 3. finally matassemblybegin/end - just once.<br><br>You can do this<br><br>><br>> Lastly, is MatZeroRowsIS exactly the same as matzerorows, except that it is
<br>> meant for just 1 row instead of consecutive no. of rows?<br><br>They are the same but one takes an array of integers while the other<br>takes an IS. Neither require "consecutive no. of rows" you can zero
<br>whatever rows you want together.<br><br> Barry<br><br>><br>> Thanks again<br>><br>><br>> On 6/11/07, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>> ><br>
> ><br>> ><br>> > On Sun, 10 Jun 2007, Ben Tay wrote:<br>> ><br>> > > Hi,<br>> > ><br>> > > I need to insert values into a matrix and then solve this poisson eqn as<br>> > > part of my cfd code. For efficiency sake, I simply use
<br>> > ><br>> > > "do j=1,size_y<br>> > ><br>> > > do i=1,size_x<br>> > ><br>> > > matsetvalue ....<br>> > ><br>> > > end do<br>> > >
<br>> > > end do"<br>> > ><br>> > > to insert values into all the cells<br>> > ><br>> > > Then for specific cells, I need to enter some other values. In other<br>> > words,
<br>> > > for specific rows of the matrix, I need to zero the whole row and insert<br>> > new<br>> > > values. How can I do that?<br>> > ><br>> > > I tried to use MatZeroRows but it says it's not for unassembled matrix.
<br>> > But<br>> > > I need to zero the particular row, insert values, and then finally<br>> > assembly<br>> > > it. Is there a command to do this?<br>> ><br>> > matassemblybegin/end
<br>> > matzerorows<br>> > matsetvalues, matsetvalues, matsetvalue<br>> > matssemblybegin/end<br>> ><br>> > For improved efficiency you will want to call<br>> > MatSetOption(mat,MAT_KEEP_ZEROED_ROWS); before the matzerorows()
<br>> ><br>> > ><br>> > > Thanks<br>> > ><br>> ><br>> ><br>><br><br></blockquote><br>