[petsc-users] error handling

Sam Guo sam.guo at cd-adapco.com
Tue Jan 21 10:49:02 CST 2020


I use PETSc from my application. Sounds you are saying I just treat ierr!=0
as an system error and no need to call Destroy functions.

On Tuesday, January 21, 2020, Smith, Barry F. <bsmith at mcs.anl.gov> wrote:

>
>
> > On Jan 20, 2020, at 6:32 PM, Sam Guo <sam.guo at cd-adapco.com> wrote:
> >
> > Hi Barry,
> >   I understand ierr != 0 means  something catastrophic. I just want to
> release all memory before I exit PETSc.
>
>    In general not possible. If you run with the debug version and
> -malloc_debug it is possible but because of the unknown error it could be
> that the releasing of the memory causes a real crash.
>
>    Is your main concern when you use PETSc for a large problem and it
> errors because it is "out of memory"?
>
>    Barry
>
>
> >
> > Thanks,
> > Sam
> >
> > On Mon, Jan 20, 2020 at 4:06 PM Smith, Barry F. <bsmith at mcs.anl.gov>
> wrote:
> >
> >   Sam,
> >
> >     I am not sure what your goal is but PETSc error return codes are
> error return codes not exceptions. They mean that something catastrophic
> happened and there is no recovery.
> >
> >     Note that PETSc solvers do not return nonzero error codes on failure
> to converge etc. You call, for example, KPSGetConvergedReason() after a KSP
> solve to see if it has failed, this is not a catastrophic failure. If a
> MatCreate() or any other call returns a nonzero ierr the game is up, you
> cannot continue running PETSc.
> >
> >    Barry
> >
> >
> > > On Jan 20, 2020, at 5:41 PM, Matthew Knepley <knepley at gmail.com>
> wrote:
> > >
> > > Not if you initialize the pointers to zero: Mat A = NULL.
> > >
> > >    Matt
> > >
> > > On Mon, Jan 20, 2020 at 6:31 PM Sam Guo <sam.guo at cd-adapco.com> wrote:
> > > I mean MatDestroy.
> > >
> > > On Mon, Jan 20, 2020 at 3:28 PM Sam Guo <sam.guo at cd-adapco.com> wrote:
> > > Does it hurt to call Destroy function without calling CreateFunction?
> For example
> > > Mat A, B;
> > > PetscErrorCode  ierr1, ierr2;
> > > ierr1 = MatCreate(PETSC_COMM_WORLD,&A);
> > > if(ierr1 == 0)
> > > {
> > >   ierr2 = MatCreate(PETSC_COMM_WORLD
> > > ,&B);
> > >
> > > }
> > > if(ierr1 !=0 || ierr2 != 0)
> > > {
> > >   Destroy(&A);
> > >   Destroy(&B); // if ierr1 !=0, MatCreat is not called on B. Does it
> hurt to call Destroy B here?
> > > }
> > >
> > >
> > >
> > > On Mon, Jan 20, 2020 at 11:11 AM Dave May <dave.mayhem23 at gmail.com>
> wrote:
> > >
> > >
> > > On Mon 20. Jan 2020 at 19:47, Sam Guo <sam.guo at cd-adapco.com> wrote:
> > > Can I assume if there is MatCreat or VecCreate, I should clean up the
> memory myself?
> > >
> > > Yes. You will need to call the matching Destroy function.
> > >
> > >
> > >
> > > On Mon, Jan 20, 2020 at 10:45 AM Sam Guo <sam.guo at cd-adapco.com>
> wrote:
> > > I only include the first few lines of SLEPc example. What about
> following
> > >   ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
> > >   ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n);CHKERRQ(ierr);
> > > Is there any memory  lost?
> > >
> > > On Mon, Jan 20, 2020 at 10:41 AM Dave May <dave.mayhem23 at gmail.com>
> wrote:
> > >
> > >
> > > On Mon 20. Jan 2020 at 19:39, Sam Guo <sam.guo at cd-adapco.com> wrote:
> > > I don't have a specific case yet. Currently every call of PETSc is
> checked. If ierr is not zero, print the error and return. For example,
> > >    Mat A; /* problem matrix */
> > >    EPS eps; /* eigenproblem solver context */
> > >    EPSType type;
> > >   PetscReal error,tol,re,im;
> > >   PetscScalar kr,ki; Vec xr,xi; 25
> > >   PetscInt n=30,i,Istart,Iend,nev,maxit,its,nconv;
> > >   PetscErrorCode ierr;
> > >   ierr = SlepcInitialize(&argc,&argv,(char*)0,help);CHKERRQ(ierr);
> > >   ierr = PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);CHKERRQ(ierr);
> > >    ierr = PetscPrintf(PETSC_COMM_WORLD,"\n1-D Laplacian Eigenproblem,
> n=%D\n\n",n);CHKERRQ(ierr);
> > >
> > > I am wondering if the memory is lost by calling CHKERRQ.
> > >
> > > No.
> > >
> > >
> > >
> > > On Mon, Jan 20, 2020 at 10:14 AM Dave May <dave.mayhem23 at gmail.com>
> wrote:
> > >
> > >
> > > On Mon 20. Jan 2020 at 19:11, Sam Guo <sam.guo at cd-adapco.com> wrote:
> > > Dear PETSc dev team,
> > >    If PETSc function returns an error, what's the correct way to clean
> PETSc?
> > >
> > > The answer depends on the error message reported. Send the complete
> error message and a better answer can be provided.
> > >
> > > Particularly how to clean up the memory?
> > >
> > > Totally depends on the objects which aren’t being freed. You need to
> provide more information
> > >
> > > Thanks
> > > Dave
> > >
> > >
> > > Thanks,
> > > Sam
> > >
> > >
> > > --
> > > What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> > > -- Norbert Wiener
> > >
> > > https://www.cse.buffalo.edu/~knepley/
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200121/5de4b12e/attachment.html>


More information about the petsc-users mailing list