<div dir="ltr">Ah, ok thank you. So let me just make sure I completely understand. When using the MatPreallocatorPreallocate() routine, since the exact sparsity pattern is specified (as opposed to just specifying the number of nnz per row), there is no need to put in extra zeros to maintain the allocated space because the routine does that for me?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 12, 2022 at 3:46 PM Junchao Zhang <<a href="mailto:junchao.zhang@gmail.com">junchao.zhang@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 12, 2022 at 12:23 PM Samuel Estes <<a href="mailto:samuelestes91@gmail.com" target="_blank">samuelestes91@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">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. <div><br></div><div>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?</div></div></blockquote><div>I think your understanding is correct.</div><div>I think the rule is: if you have not specified the exact sparsity pattern in preallocation (for example, you only said this row had this number of nonzeros, but did not give the column indices), then in MatAssebmlyEnd(), unused slots will be compressed out.</div><div>You can call MatZeroEntries() on assembled or unassembled (but preallocated) matrices. The routine just zeros the internal value array. It does not help you to preserve nonzero entries. </div><div>With MatPreallocatorPreallocate(), the sparsity is specified, so that petsc will keep the entries. <br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>Sorry for the convoluted question. I hope it's clear. </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 12, 2022 at 11:54 AM Samuel Estes <<a href="mailto:samuelestes91@gmail.com" target="_blank">samuelestes91@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>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!</div></div>
</blockquote></div>
</blockquote></div></div>
</blockquote></div>