[petsc-dev] MatAssembly removes all preallocation info

Barry Smith bsmith at mcs.anl.gov
Mon Sep 25 12:41:44 CDT 2017


> On Sep 25, 2017, at 11:22 AM, Kong, Fande <fande.kong at inl.gov> wrote:
> 
> 
> 
> On Mon, Sep 25, 2017 at 10:05 AM, Stefano Zampini <stefano.zampini at gmail.com> wrote:
> If you know the union of the different sparsity patterns, after you preallocate you can set all zeros to use all the entries. This way PETSc will not complain about new nonzeros in successive assemblies.
> 
> 
> Thanks, Stefano,
> 
> Yes, we are actually using this way right now. We are explicitly setting zeros to the matrix to stop petsc shrinking the memory.

   This 
>  But we want to know why we free the extra memory? Yes, we shrink  the memory by moving all data together to have an efficiency computation. But it is still possible to not throw away our  preallocated memory space if we  want to use latter.  

   contradicts this.

   If at the beginning you put in all the zeros you will ever need then PETSc will not "throw away" preallocated space. Most likely you are not actually setting the initial nonzero structure using the union of all future nonzero structures.

   If the nonzero structure changes dramatically over time, for instance if the mesh is moving around removing lots of old connections and introducing lots of new ones then you do not want to just preallocate. Instead you need to preallocate for each totally new nonzero structure.

   There is no way to "preserve" the initial preallocation information through later time except by explicitly putting zero entries into the matrix.

  Barry

> 
> 
> Fande,
> 
>  
> Il 25 Set 2017 7:01 PM, "Kong, Fande" <fande.kong at inl.gov> ha scritto:
> Hi Matt,
> 
> Thanks for your reply. 
> 
> The sparsity pattern is slightly different from one Newton iteration to another. We preallocate  enough memory at the beginning, and want to use that memory for the following iterations. 
> 
> Does PETSc accutally free the preallocated (extra) memory? I so cannot use it during the second iteration. 
> 
> 
> 
> Fande,
> 
> On Mon, Sep 25, 2017 at 9:43 AM, Matthew Knepley <knepley at gmail.com> wrote:
> On Mon, Sep 25, 2017 at 11:39 AM, Kong, Fande <fande.kong at inl.gov> wrote:
> Hi All,
> 
> A matrix is created with the right preallocation, and then MatAssembly is called. The preallocation info will be removed. We insert any values then, and will encounter an malloc error.
> 
> My question is that we was intending to design like this way? Attached simple example demonstrates what I am talking about. 
> 
> Yes, this is the intent. Why are you assembling? Could you use MAT_ASSEMBLY_FLUSH?
> 
>   Matt
>  
> 
> Fande,
> 
> 
> 
> -- 
> 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
> 
> https://www.cse.buffalo.edu/~knepley/
> 
> 



More information about the petsc-dev mailing list