[petsc-users] Proper way to abort/restart SNESSolve due to exceptions
Zou, Ling
ling.zou at inl.gov
Sun Apr 2 21:51:55 CDT 2017
Barry, appreciate your detailed answers. I will give it a try.
Best,
Ling
On Fri, Mar 31, 2017 at 3:45 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>
> PETSc doesn't use C++ exceptions. If a catastrophic unrecoverable error
> occurs each PETSc routine returns a nonzero error code. All the application
> can do in that case is end.
>
> If a solver does not converge then PETSc does not use a nonzero error
> code, instead you obtain information from calls to SNESGetConvergedReason()
> (or KSPGetConvergedReason()) to determine if there was a convergence
> failure or not. If there was a lack of convergence PETSc solvers still
> remain in a valid state and there is no "cleanup" on the solver objects
> needed.
>
> We have improved the PETSc handling of failed function evaluations,
> failed linear solvers etc in the past year so you MUST use the master
> branch of the PETSc repository and not the release version.
>
> So your code can look like
>
> SNESSolve()
> SNESGetConvergedReason(snes,&reason);
> if (reason < 0) dt = .5*dt;
> else no_converged = false;
>
>
> Note that the PETSc TS time-stepping object already manages stuff like
> this as well as providing local error estimate controls so it is better to
> use the PETSc TS rather than using SNES and having to manage all the
> time-stepping yourself.
>
> Barry
>
> > On Mar 31, 2017, at 10:28 AM, Zou, Ling <ling.zou at inl.gov> wrote:
> >
> > Hi All,
> >
> > I have done some researching in the PETSc email archive, but did not
> find a decent way to do it. Assume that, during a SNESSolve, something
> unphysical happening and a C++ exception is send, and now I want to stop
> the SNESSolve and let it try a smaller time step.
> > Here are some pseudo code I have:
> >
> > while(no_converged)
> > {
> > try
> > {
> > SNESSolve(...);
> > if (SNESSolve converged)
> > no_converged = false;
> > }
> > catch(int err)
> > {
> > /* do some clean work here? */
> > dt = 0.5 * dt;
> > }
> > }
> >
> > It seems to me that it is not a good way to do, as if an exception is
> thrown during SNESSolve, the code go to the error catching, changing time
> step, and immediately do SNESSolve again. I would expect that there should
> be some clean work needed before another SNESSolve call, as I commented in
> the code.
> >
> > I found two related email threads:
> > https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.
> mcs.anl.gov_pipermail_petsc-2Dusers_2014-2DAugust_022597.html&d=DwIFAg&c=
> 54IZrppPQZKX9mLzcGdPfFD1hxrcB__aEkJFOKJFd00&r=kuHHom1yjd94zUrBWecnYg&m=
> lP2oXFkw7mIXP8jrBmP9ibf6v7wu51fnRj9VeYDYS3k&s=
> RRKX6UIqdBWee88UeOAUNO8MHg6ULljCgZkCaTqCZCQ&e=
> > https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.
> mcs.anl.gov_pipermail_petsc-2Dusers_2015-2DFebruary_
> 024367.html&d=DwIFAg&c=54IZrppPQZKX9mLzcGdPfFD1hxrcB__aEkJFOKJFd00&r=
> kuHHom1yjd94zUrBWecnYg&m=lP2oXFkw7mIXP8jrBmP9ibf6v7wu51
> fnRj9VeYDYS3k&s=h1wm-wFX_C4uzDG0aa6uA7w1jAlnJmKUMvDNneULt4I&e=
> >
> > But I don't see a clear answer there.
> > Any comments on this issue?
> >
> > Best,
> >
> > Ling
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20170402/721d4b4b/attachment.html>
More information about the petsc-users
mailing list