[petsc-users] MatZeroEntries for retaining allocated space

Samuel Estes samuelestes91 at gmail.com
Tue Apr 12 12:22:51 CDT 2022


Maybe I should create a separate question for this but I did some testing
and now I'm a bit confused on how PETSc handles preallocated space which is
not assigned a value. I created a test case where I allocated a certain
amount of space for a matrix. I then only assigned a value to the (0,0)
entry and assembled the matrix. When I look at the MatInfo it says that
there were 0 unneeded entries. Furthermore, when I use MatView, I see that
there are 0 values in the matrix so there actually were values which were
put there.

I have a guess at what's happening and if I'm correct then it would solve
my original problem but I would like to confirm here. I am using the
MatPreallocator class along with the MatPreallocatorPreallocate() routine
to allocate space for the matrix. My guess is that this routine
automatically assigns a value of zero to the entries which I specified in
the preallocator. So if I had done the original MatXXXAIJSetPreallocation()
routines which just allocate a certain number of non-zeros to the rows,
then I would have to explicitly assign them zero values or else I would
lose unassigned space in the assembly routines. Since the MatPreallocator
specifies exactly which entries will be non-zero, PETSc also actually
assigns a zero value under the hood so that I don't have to explicitly
assign values myself. Is this correct?

Sorry for the convoluted question. I hope it's clear.

On Tue, Apr 12, 2022 at 11:54 AM Samuel Estes <samuelestes91 at gmail.com>
wrote:

> Hi,
>
> I have a problem where I want to allocate some nonzero structure to a
> sparse matrix which will be used repeatedly to solve some equations. The
> assembly routines will compress out allocated space which has not been
> assigned a value so I know that I need to assign zero values to any unused
> entries in order to keep that space. Will MatZeroEntries do this? If not, I
> could always just loop over and explicitly assign zero values but
> MatZeroEntries would be more convenient. Thanks!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220412/cf468daf/attachment.html>


More information about the petsc-users mailing list