<div dir="ltr"><div dir="ltr">On Thu, Jan 16, 2025 at 9:50 PM Zou, Ling via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:</div><div class="gmail_quote gmail_quote_container"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg3566928604763490365">





<div lang="EN-US" style="overflow-wrap: break-word;">
<div class="m_-3865172755537695077WordSection1">
<p class="MsoNormal"><span style="font-size:11pt">Hi all,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Does PETSc has some automatic matrix sparsity detection algorithm available?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Something like: <a href="https://urldefense.us/v3/__https://docs.sciml.ai/NonlinearSolve/stable/basics/sparsity_detection/__;!!G_uCfscf7eWS!ccEx6zmuNrVADqtN50hO2N0k4Qs-A70nztAjMLu-JElnjhK5w84BpYC8CAINd6KihSxaS2rx_LgpqUVM49U$" target="_blank">
https://docs.sciml.ai/NonlinearSolve/stable/basics/sparsity_detection/</a></span></p></div></div></div></blockquote><div><br></div><div>Sparsity detection would rely on introspection of the user code for ComputeFunction(), which is not</div><div>possible in C (unless you were to code up your evaluation in some symbolic framework).</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg3566928604763490365"><div lang="EN-US" style="overflow-wrap: break-word;"><div class="m_-3865172755537695077WordSection1">
<p class="MsoNormal"><span style="font-size:11pt">The background is that I use finite differencing plus matrix coloring to (efficiently) get the Jacobian.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">For the matrix coloring part, I color the matrix based on mesh connectivity and variable dependencies, which is not bad, but just try to be lazy to even eliminating this part.</span></p></div></div></div></blockquote><div><br></div><div>This is how the automatic frameworks also work. This is how we compute the sparsity pattern for PetscFE and PetscFV.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg3566928604763490365"><div lang="EN-US" style="overflow-wrap: break-word;"><div class="m_-3865172755537695077WordSection1">
<p class="MsoNormal"><span style="font-size:11pt">A related but different question, how much does PETSc support automatic differentiation?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">I see some old paper:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><a href="https://ftp.mcs.anl.gov/pub/tech_reports/reports/P922.pdf" target="_blank">https://ftp.mcs.anl.gov/pub/tech_reports/reports/P922.pdf</a><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">and discussion in the roadmap:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><a href="https://urldefense.us/v3/__https://petsc.org/release/community/roadmap/__;!!G_uCfscf7eWS!ccEx6zmuNrVADqtN50hO2N0k4Qs-A70nztAjMLu-JElnjhK5w84BpYC8CAINd6KihSxaS2rx_Lgpw6v6hKE$" target="_blank">https://petsc.org/release/community/roadmap/</a><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">I am thinking that if AD works so I don’t even need to do finite differencing Jacobian, or have it as another option.</span></p></div></div></div></blockquote><div><br></div><div>Other people understand that better than I do.</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="msg3566928604763490365"><div lang="EN-US" style="overflow-wrap: break-word;"><div class="m_-3865172755537695077WordSection1">
<p class="MsoNormal"><span style="font-size:11pt">Best,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">-Ling<u></u><u></u></span></p>
</div>
</div>

</div></blockquote></div><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><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="https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!dvR7knTNgJjVsN8MbdkzqHYGMeFeJA5KRmWbLart8sNlv5MD6vaocv12fo_IltMmctrA04DuDQsTXUFmc9QT$" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>