[petsc-users] Mat preallocation for adaptive grid
samuelestes91 at gmail.com
Sat Jun 11 19:32:20 CDT 2022
My question concerns preallocation for Mats in adaptive FEM problems. When
the grid refines, I destroy the old matrix and create a new one of the
appropriate (larger size). When the grid “un-refines” I just use the same
(extra large) matrix and pad the extra unused diagonal entries with 1’s.
The problem comes in with the preallocation. I use the MatPreallocator,
MatPreallocatorPreallocate() paradigm which requires a specific sparsity
pattern. When the grid un-refines, although the total number of nonzeros
allocated is (most likely) more than sufficient, the particular sparsity
pattern changes which leads to mallocs in the MatSetValues routines and
obviously I would like to avoid this.
One obvious solution is just to destroy and recreate the matrix any time
the grid changes, even if it gets smaller. By just using a new matrix every
time, I would avoid this problem although at the cost of having to rebuild
the matrix more often than necessary. This is the simplest solution from a
programming perspective and probably the one I will go with.
I'm just curious if there's an alternative that you would recommend?
Basically what I would like to do is to just change the sparsity pattern
that is created in the MatPreallocatorPreallocate() routine. I'm not sure
how it works under the hood, but in principle, it should be possible to
keep the memory allocated for the Mat values and just assign them new
column numbers and potentially add new nonzeros as well. Is there a
convenient way of doing this? One thought I had was to just fill in the
MatPreallocator object with the new sparsity pattern of the coarser mesh
and then call the MatPreallocatorPreallocate() routine again with the new
MatPreallocator matrix. I'm just not sure how exactly that would work since
it would have already been called for the FEM matrix for the previous,
Finally, does this really matter? I imagine the bottleneck (assuming good
preallocation) is in the solver so maybe it doesn't make much difference
whether or not I reuse the old matrix. In that case, going with option 1
and simply destroying and recreating the matrix would be the way to go just
to save myself some time.
I hope that my question is clear. If not, please let me know and I will
clarify. I am very curious if there's a convenient solution for the second
option I mentioned to recycle the allocated memory and redo the sparsity
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the petsc-users