PETSC memory usage

Matthew Knepley knepley at
Tue Sep 29 18:19:32 CDT 2009

On Tue, Sep 29, 2009 at 5:32 PM, Matt Funk <mafunk at> wrote:

> Hi,
> i have another question regarding how petsc uses memory w.r.t caching in
> MatSetValues .
> My code does the standard stuff:
> 1) i preallocate the memory
> 2) i insert the values via MatSetValues
> 3)i assemble it.
> Say, for example i declare a 100x100 matrix with 10 NZ entries per row.
> After 1), will the memory used for the matrix be 100^2*10*sizeof(double)?


> After 2), will the memory used be 100^2*10*sizeof(double) from the prealloc
> PLUS 100^2*10*sizeof(double) form the caching of values

Not sure what caching you mean. No extra memory will be needed. Do you mean
storing values
set for off-process rows? We refer to that as "stashing". You can clear the
stash by calling
MatAssemblyEnd() with ASSEMBLY_FLUSH.


> After 3), will the memory then be reduced back to 100^2*10*sizeof(double)?
> My concern is step 2). If it is using memory for prealloc and seperately
> for caching, then is there a way to flush the cached values to the
> preallocated slots? I tried finding stuff in the manual pages but i am not
> quite sure if i can or not.
> thanks
> matt

What most experimenters take for granted before they begin their experiments
is infinitely more interesting than any results to which their experiments
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the petsc-users mailing list