On Fri, Feb 18, 2011 at 6:29 AM, Gong Ding <span dir="ltr">&lt;<a href="mailto:gdiso@ustc.edu">gdiso@ustc.edu</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;">
<div class="im"><br>
----- Original Message -----<br>
From: &quot;Matthew Knepley&quot; &lt;<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>&gt;<br>
To: &quot;PETSc users list&quot; &lt;<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>&gt;<br>
Sent: Friday, February 18, 2011 7:44 PM<br>
Subject: Re: [petsc-users] Is it possible to free extra memory after matassemble?<br>
<br>
<br>
&gt; 2011/2/18 Gong Ding &lt;<a href="mailto:gdiso@ustc.edu">gdiso@ustc.edu</a>&gt;<br>
&gt;<br>
&gt;&gt; Hi,<br>
&gt;&gt; After update my FVM code to support higher order, I have to preallocate<br>
&gt;&gt; more memory when creating the matrix. However, only a few cells (determined<br>
&gt;&gt; at run time) needed to be high order, thus preallocated memory is overkill<br>
&gt;&gt; too much.<br>
&gt;&gt;<br>
&gt;&gt; Is it possible to add a function to reassemble the AIJ matrix to free the<br>
&gt;&gt; extra memory?<br>
&gt;&gt; Or it has already done when MatAssembly is called?<br>
&gt;&gt;<br>
&gt;<br>
&gt; This is done during MatAssemblyEnd(). However, there is no guarantee that<br>
&gt; the operating system<br>
&gt; actually returns that memory to general use.<br>
&gt;<br>
&gt;   Matt<br>
<br>
</div>I had checked the function MatAssemblyEnd_SeqAIJ in aij.c.<br>
It seems it only pack the a, i, j array, but didn&#39;t free memory.<br>
I guess one should malloc three new array with exact size and copy values to the new one, and then free the old a, i, j array?<br></blockquote><div><br></div><div>If you want that, just do MatCopy().</div><div><br></div>
<div>   Matt</div><div> </div></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>