[petsc-users] Is it possible to free extra memory after matassemble?

Gong Ding gdiso at ustc.edu
Fri Feb 18 06:29:18 CST 2011


----- Original Message ----- 
From: "Matthew Knepley" <knepley at gmail.com>
To: "PETSc users list" <petsc-users at mcs.anl.gov>
Sent: Friday, February 18, 2011 7:44 PM
Subject: Re: [petsc-users] Is it possible to free extra memory after matassemble?


> 2011/2/18 Gong Ding <gdiso at ustc.edu>
> 
>> Hi,
>> After update my FVM code to support higher order, I have to preallocate
>> more memory when creating the matrix. However, only a few cells (determined
>> at run time) needed to be high order, thus preallocated memory is overkill
>> too much.
>>
>> Is it possible to add a function to reassemble the AIJ matrix to free the
>> extra memory?
>> Or it has already done when MatAssembly is called?
>>
> 
> This is done during MatAssemblyEnd(). However, there is no guarantee that
> the operating system
> actually returns that memory to general use.
> 
>   Matt

I had checked the function MatAssemblyEnd_SeqAIJ in aij.c.
It seems it only pack the a, i, j array, but didn't free memory.
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?

  
 


More information about the petsc-users mailing list