<div dir="ltr"><div dir="ltr">On Fri, Apr 1, 2022 at 12:27 PM Samuel Estes <<a href="mailto:samuelestes91@gmail.com">samuelestes91@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I have a problem in which I know (roughly) the number of non-zero entries for each row of a matrix but I don't have a convenient way of determining whether they belong to the diagonal or off-diagonal part of the parallel matrix. Is there some way I can just allocate the total number of non-zeros in a row regardless of which part they belong to? I'm assuming that this is not possible but I just wanted to check. It seems like it should be possible in principle since the matrix is only split by the rows but the columns of a row are all on the same processor (at least as I understand it). Thanks!</div></div></blockquote><div><br></div><div>In serial, the matrix is stored by rows. In parallel, it is split into a diagonal and off-diagonal block, so that we can overlap communication and computation in the matvec.</div><div><br></div><div>However, we have a convenience structure for figuring this out, called MatPreallocator, <a href="https://petsc.org/main/docs/manualpages/Mat/MATPREALLOCATOR.html">https://petsc.org/main/docs/manualpages/Mat/MATPREALLOCATOR.html</a></div><div>In my code, I wrote a loop around the code that filled up my matrix, which executed twice. On the first pass, I fed in the MatPreallocator matrix. When this finished</div><div>you can call <a href="https://petsc.org/main/docs/manualpages/Mat/MatPreallocatorPreallocate.html#MatPreallocatorPreallocate">https://petsc.org/main/docs/manualpages/Mat/MatPreallocatorPreallocate.html#MatPreallocatorPreallocate</a> on your system amtrix, then on the second</div><div>pass use the system matrix. This was only a few extra lines of code for me. If you want to optimize further, you can have a flag that only computes the values on the</div><div>second pass.</div><div><br></div><div>  Thanks,</div><div><br></div><div>      Matt</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Sam</div></div></blockquote></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>