<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 28, 2020 at 9:14 PM Yuyun Yang <<a href="mailto:yyang85@stanford.edu">yyang85@stanford.edu</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>
<div dir="auto" style="direction:ltr;margin:0px;padding:0px;font-family:sans-serif;font-size:11pt;color:black">
Thanks for the explanations. Yes they are identical if no preconditioner is applied.
<br>
<br>
</div>
<div dir="auto" style="direction:ltr;margin:0px;padding:0px;font-family:sans-serif;font-size:11pt;color:black">
A follow-up question on this: in the case of a changing matrix at every time step, it's necessary for my code to destroy and re-assemble the matrix every time, </div></div></blockquote><div><br></div><div>No,</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><div dir="auto" style="direction:ltr;margin:0px;padding:0px;font-family:sans-serif;font-size:11pt;color:black">so I was wondering whether the matrix-free method, even though with no preconditioner the KSP convergence
 is slower, would have any advantage by saving the matrix assembly step? </div></div></blockquote><div><br></div><div>Yes.</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><div dir="auto" style="direction:ltr;margin:0px;padding:0px;font-family:sans-serif;font-size:11pt;color:black">Or the time saved by that is insignificant compared to the slowdown in KSP with a preconditioned matrix?<br></div></div></blockquote><div><br></div><div>This problem dependent, but probably yes. You can also use a matrix-free operator and a stored matrix preconditioner matrix. That is why KSPSetOpertarors takes two matrices. Then you can "lag" the preconditioner and just update it when it pays off.</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><div dir="auto" style="direction:ltr;margin:0px;padding:0px;font-family:sans-serif;font-size:11pt;color:black">
<br>
</div>
<div dir="auto" style="direction:ltr;margin:0px;padding:0px;font-family:sans-serif;font-size:11pt;color:black">
Thank you,<br>
</div>
<div dir="auto" style="direction:ltr;margin:0px;padding:0px;font-family:sans-serif;font-size:11pt;color:black">
Yuyun<br>
<br>
</div>
<div dir="auto" style="direction:ltr;margin:0px;padding:0px;font-family:sans-serif;font-size:11pt;color:black">
<span id="gmail-m_8748324454915725754OutlookSignature">
<div dir="auto" style="direction:ltr;margin:0px;padding:0px;font-family:sans-serif;font-size:11pt;color:black">
获取 <a href="https://aka.ms/ghei36" target="_blank">Outlook for Android</a></div>
</span><br>
</div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_8748324454915725754divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Mark Adams <<a href="mailto:mfadams@lbl.gov" target="_blank">mfadams@lbl.gov</a>><br>
<b>Sent:</b> Saturday, March 28, 2020 10:29:14 PM<br>
<b>To:</b> Jed Brown <<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>><br>
<b>Cc:</b> Yuyun Yang <<a href="mailto:yyang85@stanford.edu" target="_blank">yyang85@stanford.edu</a>>; <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] Speed of KSPSolve using Matshell vs. regular matrix</font>
<div> </div>
</div>
<div>
<div dir="ltr">I think Yuyun is saying "....<span style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px">inevitable to encounter significant slowdown compared to using a fully assembled matrix
<b>with a suitable preconditioner</b>? </span>"
<div><br>
</div>
<div>You convergence rate will basically always be better with a preconditioner and unless you are solving the identity (mass matrix) then it will often be significant.</div>
<div><br>
</div>
<div>Jed is responding to comparing un-preconditioned matrix vs matrix-free and you do want to check that they are identical if you think you have an exact Jacobian of a linear problem.</div>
<div><br>
</div>
</div>
<br>
<div>
<div dir="ltr">On Sat, Mar 28, 2020 at 9:54 AM Jed Brown <<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>> wrote:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
If the number of iterations is (significantly) different, then you'd<br>
have to debug why your code doesn't implement the same linear operator.<br>
You can use MatComputeOperator or -ksp_view_mat_explicit to help reveal<br>
differences.<br>
<br>
If the number of iterations is the same but your code is slower, then<br>
you'd have to optimize the performance of your code.<br>
<br>
Yuyun Yang <<a href="mailto:yyang85@stanford.edu" target="_blank">yyang85@stanford.edu</a>> writes:<br>
<br>
> Hello team,<br>
><br>
> If I use KSPSolve for Ax=b using Matshell (a user-defined stencil equivalent of A) without preconditioning (since the standard PC would need information of the matrix so cannot apply it to matrix-free method), is it possible, or even inevitable to encounter
 significant slowdown compared to using a fully assembled matrix with a suitable preconditioner? I'm running a small example and it's already taking a long time for Matshell to converge.<br>
><br>
> Thanks for your help,<br>
> Yuyun<br>
</blockquote>
</div>
</div>
</div>

</blockquote></div></div>