<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div> Anthony,<div class=""><br class=""></div><div class=""> Keeping the nonzero locations (with zero in them) will be a bit faster in the call to MatZeroRows() because otherwise it has to shift all the entries in the sparse matrix arrays data structures to "remove" the unneeded locations. </div><div class=""> </div><div class=""> But the real question is how it affects times in later function calls</div><div class=""><br class=""></div><div class="">1) If you do the MatSetValues()/MatAssemblyBegin/End() repeatedly it will be much faster if you keep the nonzero locations (with zero in them). </div><div class=""><br class=""></div><div class="">2) Time for MatMult() will be a bit faster if you remove the locations, but the depending on the preconditioner the preconditioner may be more or less effective and a bit slower or faster. </div><div class=""><br class=""></div><div class=""> So, rule of thumb is if you only do MatZeroRows() once you might generally remove the locations but if it is done in a loop with the same matrix (over time-steps for example, or even in SNES) you want to keep the nonzero locations.</div><div class=""><br class=""></div><div class=""> Barry</div><div class=""><br class=""></div><div class="">Note: in both cases the memory usage is the same because PETSc does not "return" the excessive memory.</div><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Aug 13, 2020, at 8:07 AM, Matthew Knepley <<a href="mailto:knepley@gmail.com" class="">knepley@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class="">On Thu, Aug 13, 2020 at 3:17 AM Anthony Paul Haas <<a href="mailto:aph@email.arizona.edu" class="">aph@email.arizona.edu</a>> wrote:<br class=""></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" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><font face="arial, sans-serif" class="">Hello,</font><div class=""><font face="arial, sans-serif" class=""><br class=""></font></div><div class=""><font face="arial, sans-serif" class="">I am using MatZeroRows for imposing a known forcing into my equations in conjunction with rhs and by setting the diagonal of the matrix to 1.</font></div><div class=""><font face="arial, sans-serif" class=""><br class=""></font></div><div class=""><font face="arial, sans-serif" class="">I am using Fortran. I have used:</font></div><div class=""><font face="arial, sans-serif" class=""><br class=""></font></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(203, 36, 24);" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><font face="arial, sans-serif" class="">! only local processors set their own zeros </font></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="arial, sans-serif" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(194,0,255)" class="">call</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(74,0,255)" class="">MatSetOption</span><span style="font-variant-ligatures:no-common-ligatures" class="">(self%fieldLHSMat_ps, MAT_NO_OFF_PROC_ZERO_ROWS, PETSC_TRUE, ierr)</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="arial, sans-serif" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="arial, sans-serif" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(194,0,255)" class="">call</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(74,0,255)" class="">MatSetOption</span><span style="font-variant-ligatures:no-common-ligatures" class="">(self%fieldLHSMat_ps, MAT_KEEP_NONZERO_PATTERN, PETSC_TRUE, ierr)</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal; min-height: 13px;" class=""><font face="arial, sans-serif" class=""><br class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="arial, sans-serif" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(194,0,255)" class="">call</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(74,0,255)" class="">MatZeroRows</span><span style="font-variant-ligatures:no-common-ligatures" class="">(self%fieldLHSMat_ps, numrows, glob_row_idx, diag, PETSC_NULL_OBJECT, PETSC_NULL_OBJECT, ierr)</span></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><font face="arial, sans-serif" class=""><br class=""></font></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><font face="arial, sans-serif" class=""><br class=""></font></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><font face="arial, sans-serif" class="">Is numrows above the local (on each proc.) number of rows to remove, or is it the global number of rows to remove?</font></span></div></div></div></div></div></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">Local.</div><div class=""> </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" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="arial, sans-serif" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Also on some processors, I have no rows to remove, hence the array </span>glob_row_idx is not allocated. How can I tell Petsc? Should I pass PETSC_NULL_OBJECT instead of glob_row_idx in this case? </font></div></div></div></div></div></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">If you pass numrows = 0, it should not matter what is in the next slot, as long as it type checks.</div><div class=""> </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" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="arial, sans-serif" class="">Finally, does using the option MAT_KEEP_NONZERO_PATTERN have an influence on the time the MatZeroRows call will take?</font></div></div></div></div></div></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">I don't think it makes much of a difference, but I have not measured it.</div><div class=""><br class=""></div><div class=""> Thanks,</div><div class=""><br class=""></div><div class=""> Matt</div><div class=""> </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" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="arial, sans-serif" class="">Thanks,</font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="arial, sans-serif" class=""><br class=""></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="arial, sans-serif" class="">Best regards,</font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="arial, sans-serif" class=""><br class=""></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="arial, sans-serif" class="">Anthony</font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="arial, sans-serif" class=""><br class=""></font></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><font face="arial, sans-serif" class=""><br class=""></font></div></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div></div></div></div></div></div></div></div>
</blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class="">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br class="">-- Norbert Wiener</div><div class=""><br class=""></div><div class=""><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank" class="">https://www.cse.buffalo.edu/~knepley/</a><br class=""></div></div></div></div></div></div></div></div>
</div></blockquote></div><br class=""></div></body></html>