On Fri, Feb 3, 2012 at 4:46 PM, Margarita Satraki <span dir="ltr">&lt;<a href="mailto:margarita.satraki@gmail.com">margarita.satraki@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Jed,<br><br>Thanks for the reply.<br>I&#39;ve defined 2 nonzeros per row so it should consider them to be in the correct place (1 for diagonal and 1 for the 1st off diagonal). I do not want to delete anything, just experiment with inserting new entries. This is a simple example to demonstrate my problem with a more complicated code of nonlinear elasticity.</blockquote>
<div><br></div><div>Assembly of a matrix compresses it, throwing away extra allocated places that were not used.</div><div><br></div><div>   Matt</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888">Margarita</font></span><div class="HOEnZb"><div class="h5"><br><br><div class="gmail_quote">On 3 February 2012 22:41, Jed Brown <span dir="ltr">&lt;<a href="mailto:jedbrown@mcs.anl.gov" target="_blank">jedbrown@mcs.anl.gov</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div class="gmail_quote">On Sat, Feb 4, 2012 at 01:35, Margarita Satraki <span dir="ltr">&lt;<a href="mailto:margarita.satraki@gmail.com" target="_blank">margarita.satraki@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It seems that only the 1st case gives good results in the sense that by increasing the size of the matrix you increase the time needed by MatSetValues linearly. Both the 2nd and the 3rd case give similar results, much worse than the 1st. I understand that the 1st case has the advantage because of accurate memory allocation but shouldn&#39;t the 2ndcase be better than the 3rd since it at least defines the number of nonzeros per row so it again allocates memory more accurately?</blockquote>


</div><br></div><div>Those nonzeros are in the wrong place and PETSc does not know that you want to &quot;delete&quot; the old entries.</div><div><br></div><div>Just preallocate the correct number of nonzeros and it will be fast, don&#39;t bother with copying in a &quot;similar&quot; matrix.</div>


</div>
</blockquote></div><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>