[petsc-users] Speed of KSPSolve using Matshell vs. regular matrix

Mark Adams mfadams at lbl.gov
Sun Mar 29 04:41:52 CDT 2020


On Sat, Mar 28, 2020 at 9:14 PM Yuyun Yang <yyang85 at stanford.edu> wrote:

> Thanks for the explanations. Yes they are identical if no preconditioner
> is applied.
>
> 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,
>

No,


> 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?
>

Yes.


> Or the time saved by that is insignificant compared to the slowdown in KSP
> with a preconditioned matrix?
>

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.


>
> Thank you,
> Yuyun
>
> 获取 Outlook for Android <https://aka.ms/ghei36>
>
> ------------------------------
> *From:* Mark Adams <mfadams at lbl.gov>
> *Sent:* Saturday, March 28, 2020 10:29:14 PM
> *To:* Jed Brown <jed at jedbrown.org>
> *Cc:* Yuyun Yang <yyang85 at stanford.edu>; petsc-users at mcs.anl.gov <
> petsc-users at mcs.anl.gov>
> *Subject:* Re: [petsc-users] Speed of KSPSolve using Matshell vs. regular
> matrix
>
> I think Yuyun is saying "....inevitable to encounter significant slowdown
> compared to using a fully assembled matrix *with a suitable
> preconditioner*? "
>
> 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.
>
> 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.
>
>
> On Sat, Mar 28, 2020 at 9:54 AM Jed Brown <jed at jedbrown.org> wrote:
>
> If the number of iterations is (significantly) different, then you'd
> have to debug why your code doesn't implement the same linear operator.
> You can use MatComputeOperator or -ksp_view_mat_explicit to help reveal
> differences.
>
> If the number of iterations is the same but your code is slower, then
> you'd have to optimize the performance of your code.
>
> Yuyun Yang <yyang85 at stanford.edu> writes:
>
> > Hello team,
> >
> > 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.
> >
> > Thanks for your help,
> > Yuyun
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200329/f136c167/attachment.html>


More information about the petsc-users mailing list