<div dir="ltr"><div dir="ltr">On Wed, Nov 30, 2022 at 7:51 AM 김성익 <<a href="mailto:ksi2443@gmail.com">ksi2443@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">Thank you for your comments.<br>However, I have more questions.<div><br></div><div>1. Generally, (KSPCreate, KSPSetOperators, KSPGetPC, PCSetType, PCFactorSetMatSolverType, KSPSetFromOptions )<br>above functions are should be called after each "MatassemblyEnd??"</div></div></blockquote><div><br></div><div>KSPCreate is called once.</div><div><br></div><div>You do not need PCSetType, PCFactorSetMatSolverType, KSPSetFromOptions more than once, unless you want to change the solver type.</div><div><br></div><div>KSPSetOperators is called if you want to change the system matrix.<br></div><div><br></div><div>KSPSolve is called when you want to change the rhs.</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 dir="ltr"><div>2. Though reading the user guide, I don't fully understand under what circumstances the functions mentioned above should be called again. Can you explain when each function should be called?<br><div><br></div></div><div>Thanks,</div><div><br></div><div>Hyung Kim</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">2022년 11월 30일 (수) 오후 8:37, Mark Adams <<a href="mailto:mfadams@lbl.gov" target="_blank">mfadams@lbl.gov</a>>님이 작성:<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 dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Nov 30, 2022 at 5:08 AM 김성익 <<a href="mailto:ksi2443@gmail.com" target="_blank">ksi2443@gmail.com</a>> wrote:<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"><p class="MsoNormal" style="margin:0cm 0cm 8pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US">Hello,</span></p>
<p class="MsoNormal" style="margin:0cm 0cm 8pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin:0cm 0cm 8pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US">I’m working on FEM using PETSc.</span></p>
<p class="MsoNormal" style="margin:0cm 0cm 8pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US">As everyone knows, it is necessary to repeatedly
solve Ax=B.</span></p>
<p class="MsoNormal" style="margin:0cm 0cm 8pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US">Regarding this, I have 4 questions.</span></p>
<p class="MsoNormal" style="margin:0cm 0cm 8pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US"> </span></p>
<p style="margin:0cm 0cm 8pt 38pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US">1.<span style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:7pt;line-height:normal;font-family:"Times New Roman"">
</span></span><span lang="EN-US">There are many steps for preparing
KSPSolve. For example KSPcreate, KSPSetOperators, KSPGetPC, PCSetType, PCFactorSetMatSolverType,
KSPSetFromOptions…<br>
In Nonlinear FEM, there are repeatedly kspsolve for getting answer vector. Is it
correct to do all of the aforementioned processes (KSPcreate, KSPSetOperators ~~~)
for each KSPSolve? Or should I declare it only once at the beginning and not call
it again?</span></p></div></blockquote><div><br></div><div>You just do these once at setup but for nonlinear problems KSPSetOperators tells the solver that you have a new matrix and so "matrix setup" work needs to be done.<br></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">
<p class="MsoNormal" style="margin:0cm 0cm 8pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US"> </span></p>
<p style="margin:0cm 0cm 8pt 38pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US">2.<span style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:7pt;line-height:normal;font-family:"Times New Roman"">
</span></span><span lang="EN-US">If the answer to question 1 is
that it must be repeated every time, should this work be done right before
kspsolve, that is, when the global matrix assembly is finished, or is it
irrelevant to performance at any time?</span></p></div></blockquote><div><br></div><div>KSPSetOperators should be set after the new matrix values are set but it might work before. It just sets a pointer to the matrix and flags it as not setup.<br></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 dir="ltr">
<p class="MsoNormal" style="margin:0cm 0cm 8pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US"> </span></p>
<p style="margin:0cm 0cm 8pt 38pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US">3.<span style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:7pt;line-height:normal;font-family:"Times New Roman"">
</span></span><span lang="EN-US">When performing FEM, local
matrices are often scattered in global matrices depending on connectivity. In
this case, which is better in terms of performance: adding the values one by
one with MatSetValue or adding them all at once with MatSetValues even if they
are scattered?</span></p></div></blockquote><div><br></div><div>You want to add one element matrix at a time, generally.</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 dir="ltr">
<p style="margin:0cm 0cm 8pt 40pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin:0cm 0cm 8pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US"> </span></p>
<p style="margin:0cm 0cm 8pt 38pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US">4.<span style="font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:7pt;line-height:normal;font-family:"Times New Roman"">
</span></span><span lang="EN-US">I would like to measure the time
of each section of the process. Which method is recommended?</span></p></div></blockquote><div><br></div><div>PETSc methods are timed separateluy, but setup gets folded into KSPSolve unless you call SNESSetUp before the SNES[KSP]Solve.</div><div>You can add you own timers also <a href="https://petsc.org/release/docs/manualpages/Profiling/PetscLogEventRegister/" target="_blank">https://petsc.org/release/docs/manualpages/Profiling/PetscLogEventRegister/</a></div><div><br></div><div>Mark</div><div><br></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 dir="ltr">
<p class="MsoNormal" style="margin:0cm 0cm 8pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin:0cm 0cm 8pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US">Thank you for your help.</span></p>
<p class="MsoNormal" style="margin:0cm 0cm 8pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin:0cm 0cm 8pt;text-align:justify;line-height:107%;font-size:10pt;font-family:"\00b9d1\00c740 \00ace0\00b515""><span lang="EN-US">Hyung Kim</span></p></div>
</blockquote></div></div>
</blockquote></div>
</blockquote></div><br clear="all"><div><br></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>