[petsc-users] free unused allocated nonzeros after overestimating preallocation

Matthew Knepley knepley at gmail.com
Mon May 3 08:20:44 CDT 2010


On Mon, May 3, 2010 at 8:15 AM, Sander Land <sander.land at comlab.ox.ac.uk>wrote:

> Hi,
>
> I am preallocating a matrix using
>  MatMPIAIJSetPreallocation(HalfM,27,PETSC_NULL,26,PETSC_NULL);
> Since I have no easy way to know whether the entries will end up in
> petsc's 'diagonal' or 'nondiagonal'. After assembling the matrix this
> results in:
>
> Matrix Object:
>  type=mpiaij, rows=9801, cols=9801
>  total: nonzeros=231601, allocated nonzeros=519453
>   [0] Local rows 9801 nz 231601 nz alloced 519453 mem 6551364, not
> using I-node routines
>   [0] on-diagonal part: nz 231601
>   [0] off-diagonal part: nz 0
>
> On 1 processor, and some numbers split between on/off on more, as
> expected. So far no problem since I can temporarily spare the memory
> for 1 such matrix.
> Next, I would like to compress the storage somehow, to free the memory
> not used, since I know this nonzero pattern will not change, but I
> can't find a way to do this in petsc.
> Worse, when I use MatConvert/MatDuplicate to initialize my other
> matrices, they all seem to inherit this property of using about twice
> as much memory as needed. This is a problem when taking the number of
> rows to 1 million +.
>
> What is the easiest way to free the unused memory?
>

MatAssemblyBegin/End() frees the unused memory, so you must be calculating
the
amount of memory needed incorrectly. Remember that memory is necessary not
only
for the values, but the indexing structures.

   Matt


> Thanks,
> Sander Land
>



-- 
What most experimenters take for granted before they begin their experiments
is infinitely more interesting than any results to which their experiments
lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20100503/d2efa519/attachment.htm>


More information about the petsc-users mailing list