On Fri, Feb 18, 2011 at 6:29 AM, Gong Ding <span dir="ltr"><<a href="mailto:gdiso@ustc.edu">gdiso@ustc.edu</a>></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: "Matthew Knepley" <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>><br>
To: "PETSc users list" <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>><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>
> 2011/2/18 Gong Ding <<a href="mailto:gdiso@ustc.edu">gdiso@ustc.edu</a>><br>
><br>
>> Hi,<br>
>> After update my FVM code to support higher order, I have to preallocate<br>
>> more memory when creating the matrix. However, only a few cells (determined<br>
>> at run time) needed to be high order, thus preallocated memory is overkill<br>
>> too much.<br>
>><br>
>> Is it possible to add a function to reassemble the AIJ matrix to free the<br>
>> extra memory?<br>
>> Or it has already done when MatAssembly is called?<br>
>><br>
><br>
> This is done during MatAssemblyEnd(). However, there is no guarantee that<br>
> the operating system<br>
> actually returns that memory to general use.<br>
><br>
> 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'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>