Great, thanks for your help!<br><br>Margarita<br><br><div class="gmail_quote">On 3 February 2012 23:27, Matthew Knepley <span dir="ltr">&lt;<a href="mailto:knepley@gmail.com">knepley@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">
<div class="im">On Fri, Feb 3, 2012 at 5:05 PM, Margarita Satraki <span dir="ltr">&lt;<a href="mailto:margarita.satraki@gmail.com" target="_blank">margarita.satraki@gmail.com</a>&gt;</span> wrote:<br></div><div class="gmail_quote">
<div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Does the same happen with MatDuplicate? It overwrites the MatSeqAIJSetPreallocation?<br></blockquote><div><br></div></div><div>Yes.</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

In this case, can I redefine the nonzero places?<br></blockquote><div><br></div></div><div>No.</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I need it for the case of creating the preconditioner by changing the jacobian slightly.<br>
</blockquote><div><br></div></div><div>The right way to do this is just fully allocate the preconditioner. We have benchmarked</div><div>this hundreds of times, and it is negligible.</div><div><br></div><div>  Thanks,</div>
<div class="im"><div>
<br></div><div>     Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Margarita<br><br><div class="gmail_quote">On 3 February 2012 22:58, Matthew Knepley <span dir="ltr">&lt;<a href="mailto:knepley@gmail.com" target="_blank">knepley@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">
<div>On Fri, Feb 3, 2012 at 4:46 PM, Margarita Satraki <span dir="ltr">&lt;<a href="mailto:margarita.satraki@gmail.com" target="_blank">margarita.satraki@gmail.com</a>&gt;</span> wrote:<br></div><div class="gmail_quote">


<div><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><div>Assembly of a matrix compresses it, throwing away extra allocated places that were not used.</div><div><br></div><div>   Matt</div><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><font color="#888888">Margarita</font></span><div><div><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></div><span><font color="#888888"><br><br clear="all"><span><font color="#888888"><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>
</font></span></font></span></blockquote></div><br>
</blockquote></div></div><div class="HOEnZb"><div class="h5"><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>
</div></div></blockquote></div><br>