<div class="gmail_quote">On Thu, Nov 24, 2011 at 07:46, Dominik Szczerba <span dir="ltr">&lt;<a href="mailto:dominik@itis.ethz.ch">dominik@itis.ethz.ch</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":1uv">Yes, that is true, but 1) within the overshot preallocation margin 2)<br>
I do it at each execution of the loop, so I do not see why only the<br>
second time there are mallocs. I display mallocs directly before<br>
KSPSolve().<br></div></blockquote><div><br></div><div>The matrix is compacted. The implementation (MatSeqAIJSetPreallocation_SeqAIJ) could be changed to analyze the newly prescribed preallocation relative to the old allocation and determine that it can fit within the old storage. The problem here is that someone might specifically preallocate smaller because they want to free the old storage. So maybe we should just recognize an exact match, but what if the user called MatCreateMPIAIJWithSplitArrays() (so they still own the arrays) and they are calling this preallocation routine because they want to reuse the arrays for something else?</div>
<div><br></div><div>If we can settle on some understandable semantics for when freeing and reallocating makes sense, then we can put it in.</div><div><br></div><div>Or you could insert zeros into those locations that might be used later.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div id=":1uv">
<div class="im"><br>
&gt; I suggest assembling all possible entries (even the ones that happen to be<br>
&gt; zero) in the first assembly. Then there will be space and you can reuse the<br>
&gt; data structure.<br>
<br>
</div>This will require a bigger change in my code. Is always calling<br>
MatMPIAIJSetPreallocation a bad (inefficient) alternative?</div></blockquote></div><br><div>Depends on the availability of memory, but probably not. Always profile.</div>