<div dir="ltr"><div dir="ltr">On Thu, Jan 16, 2025 at 10:43 PM Zou, Ling <<a href="mailto:lzou@anl.gov">lzou@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="msg6510721863087075056">





<div lang="EN-US" style="overflow-wrap: break-word;">
<div class="m_6510721863087075056WordSection1">
<p class="MsoNormal"><span style="font-size:11pt">Thank you, Matt.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Seems that at least the matrix coloring part I am following the ‘best practice’.</span></p></div></div></div></blockquote><div><br></div><div>Yes, for FD approximations of the Jacobian.</div><div><br></div><div>If you have a stencil operation (like FEM or FVM), then AD can be very useful because you</div><div>only have to differentiate the kernel to get the Jacobian kernel.</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="msg6510721863087075056"><div lang="EN-US" style="overflow-wrap: break-word;"><div class="m_6510721863087075056WordSection1"><p class="MsoNormal"><span style="font-size:11pt"> </span></p>
<p class="MsoNormal"><span style="font-size:11pt">-Ling<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"><u></u> <u></u></span></p>
<div id="m_6510721863087075056mail-editor-reference-message-container">
<div>
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(181,196,223);padding:3pt 0in 0in">
<p class="MsoNormal" style="margin-bottom:12pt"><b><span style="font-size:12pt;color:black">From:
</span></b><span style="font-size:12pt;color:black">Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>><br>
<b>Date: </b>Thursday, January 16, 2025 at 9:01</span><span style="font-size:12pt;font-family:Arial,sans-serif;color:black"> </span><span style="font-size:12pt;color:black">PM<br>
<b>To: </b>Zou, Ling <<a href="mailto:lzou@anl.gov" target="_blank">lzou@anl.gov</a>><br>
<b>Cc: </b><a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a> <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>><br>
<b>Subject: </b>Re: [petsc-users] Auto sparsity detection?<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:1pt;color:white">On Thu, Jan 16, 2025 at 9:</span><span style="font-size:1pt;font-family:Arial,sans-serif;color:white"> </span><span style="font-size:1pt;color:white">50 PM
 Zou, Ling via petsc-users <petsc-users@</span><span style="font-size:1pt;font-family:Arial,sans-serif;color:white"> </span><span style="font-size:1pt;color:white">mcs.</span><span style="font-size:1pt;font-family:Arial,sans-serif;color:white"> </span><span style="font-size:1pt;color:white">anl.</span><span style="font-size:1pt;font-family:Arial,sans-serif;color:white"> </span><span style="font-size:1pt;color:white">gov>
 wrote: Hi all, Does PETSc has some automatic matrix sparsity detection algorithm available? Something like: https:</span><span style="font-size:1pt;font-family:Arial,sans-serif;color:white"> </span><span style="font-size:1pt;color:white">//docs.</span><span style="font-size:1pt;font-family:Arial,sans-serif;color:white"> </span><span style="font-size:1pt;color:white">sciml.</span><span style="font-size:1pt;font-family:Arial,sans-serif;color:white"> </span><span style="font-size:1pt;color:white">ai/NonlinearSolve/stable/basics/sparsity_detection/<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:1pt;color:white">ZjQcmQRYFpfptBannerStart<u></u><u></u></span></p>
</div>
<div style="border-width:initial;border-right-style:none;border-bottom-style:none;border-left-style:none;border-right-color:initial;border-bottom-color:initial;border-left-color:initial;display:block;text-align:left;margin:0px;padding:16px;border-radius:4px;min-width:200px;background-color:rgb(208,216,220);border-top-style:initial;border-top-color:rgb(144,164,174)" id="m_6510721863087075056pfptBannert0a6dmn">
<div id="m_6510721863087075056pfptBannert0a6dmn">
<div id="m_6510721863087075056pfptBannert0a6dmn">
<p class="MsoNormal" style="line-height:13.5pt;background:rgb(208,216,220)"><b><span style="font-size:12pt;font-family:Arial,sans-serif;color:black">This Message Is From an External Sender
<u></u><u></u></span></b></p>
</div>
<div id="m_6510721863087075056pfptBannert0a6dmn">
<p class="MsoNormal" style="line-height:13.5pt;background:rgb(208,216,220)"><span style="font-size:12pt;font-family:Arial,sans-serif;color:black">This message came from outside your organization.
<u></u><u></u></span></p>
</div>
</div>
<div>
<p class="MsoNormal" style="background:rgb(208,216,220)"><span style="font-size:12pt;color:black"> </span><span style="font-size:12pt"><u></u><u></u></span></p>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:1pt;color:white">ZjQcmQRYFpfptBannerEnd<u></u><u></u></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12pt">On Thu, Jan 16, 2025 at 9:50</span><span style="font-size:12pt;font-family:Arial,sans-serif"> </span><span style="font-size:12pt">PM Zou, Ling via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>>
 wrote:<u></u><u></u></span></p>
</div>
<div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">Hi all,</span><span style="font-size:12pt"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"> </span><span style="font-size:12pt"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">Does PETSc has some automatic matrix sparsity detection algorithm available?</span><span style="font-size:12pt"><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><span style="font-size:12pt"><u></u><u></u></span></p>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><span style="font-size:12pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt">Sparsity detection would rely on introspection of the user code for ComputeFunction(), which is not<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt">possible in C (unless you were to code up your evaluation in some symbolic framework).<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt"> <u></u><u></u></span></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">The background is that I use finite differencing plus matrix coloring to (efficiently) get the Jacobian.</span><span style="font-size:12pt"><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><span style="font-size:12pt"><u></u><u></u></span></p>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><span style="font-size:12pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt">This is how the automatic frameworks also work. This is how we compute the sparsity pattern for PetscFE and PetscFV.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt"> <u></u><u></u></span></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">A related but different question, how much does PETSc support automatic differentiation?</span><span style="font-size:12pt"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">I see some old paper:</span><span style="font-size:12pt"><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></span><span style="font-size:12pt"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">and discussion in the roadmap:</span><span style="font-size:12pt"><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></span><span style="font-size:12pt"><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><span style="font-size:12pt"><u></u><u></u></span></p>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><span style="font-size:12pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt">Other people understand that better than I do.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt">  Thanks,<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt">     Matt<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt"> <u></u><u></u></span></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11pt">Best,</span><span style="font-size:12pt"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt"> </span><span style="font-size:12pt"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt">-Ling</span><span style="font-size:12pt"><u></u><u></u></span></p>
</div>
</div>
</div>
</blockquote>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt"><br clear="all">
<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt"><u></u> <u></u></span></p>
</div>
<p class="MsoNormal"><span class="m_6510721863087075056gmailsignatureprefix"><span style="font-size:12pt">--
</span></span><span style="font-size:12pt"><u></u><u></u></span></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12pt">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<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt"><a href="https://urldefense.us/v3/__http:/www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!d-7O5V0pNvm_fDSKhNk_ilXP0jG-_MBnectBJ0BfVPOSzARXvYWAahGyRNf1cKCh9dJKEiFt2caV$" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><u></u><u></u></span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</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!cWyHnKq-Gzasz3ooIUAgTl0RTGrzg0fW8jwVOi0AHE_Ydv4dnayXiG06EPQYvp6guWhXYTv8DMnOu7xNNzJR$" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>