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

Sander Land sander.land at comlab.ox.ac.uk
Mon May 3 09:10:43 CDT 2010


Thanks for the quick answers everyone.

I was using 8 matrices of 1.03 million rows each, and my memory usage
went off to 3+ GB, whereas I was expecting around twice (8 ×
1030301×27×sizeof(double)  < 1 GB)
Looking at the actual mem usage of the duplicated matrices, it seems
that this is not inherited, but just more than I was expecting in the
first place, and the wrong "allocated nonzeros" entry threw me off.

Matrix Object:
  type=mpiaij, rows=1030301, cols=1030301
  total: nonzeros=27270901, allocated nonzeros=54605953
    [0] Local rows 1030301 nz 27270901 nz alloced 54605953 mem
688245364, not using I-node routines

MatDuplicate'd :

Matrix Object:
  type=mpiaij, rows=1030301, cols=1030301
  total: nonzeros=27270901, allocated nonzeros=54605953
    [0] Local rows 1030301 nz 27270901 nz alloced 54605953 mem
360224748, not using I-node routines

I guess MAT_SHARE_NONZERO_PATTERN could help reduce this, but my
current version (ubuntu package) doesn't have this, so I'm going to
recompile from sources.


On Mon, May 3, 2010 at 2:40 PM, Jed Brown <jed at 59a2.org> wrote:
> On Mon, 3 May 2010 08:20:44 -0500, Matthew Knepley <knepley at gmail.com> wrote:
>> MatAssemblyBegin/End() frees the unused memory, so you must be
>> calculating the amount of memory needed incorrectly.
>
> It compacts the values but does not free the extra memory.  It would be
> easy to add a matrix option to allocate new space for the entries and
> column indices, then copy the entries over, but requires too much memory
> to do it by default.
>
> MatDuplicate on the other hand only allocates for the used values, but
> copies the "maxnz" field so it will incorrectly report more allocation
> than there really is.
>
> Jed
>


More information about the petsc-users mailing list