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.<br><br>On Tuesday, January 21, 2020, Smith, Barry F. <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Jan 20, 2020, at 6:32 PM, Sam Guo <<a href="mailto:sam.guo@cd-adapco.com">sam.guo@cd-adapco.com</a>> wrote:<br>
> <br>
> Hi Barry,<br>
> I understand ierr != 0 means something catastrophic. I just want to release all memory before I exit PETSc.<br>
<br>
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.<br>
<br>
Is your main concern when you use PETSc for a large problem and it errors because it is "out of memory"?<br>
<br>
Barry<br>
<br>
<br>
> <br>
> Thanks,<br>
> Sam<br>
> <br>
> On Mon, Jan 20, 2020 at 4:06 PM Smith, Barry F. <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
> <br>
> Sam,<br>
> <br>
> 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. <br>
> <br>
> 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.<br>
> <br>
> Barry<br>
> <br>
> <br>
> > On Jan 20, 2020, at 5:41 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> wrote:<br>
> > <br>
> > Not if you initialize the pointers to zero: Mat A = NULL.<br>
> > <br>
> > Matt<br>
> > <br>
> > On Mon, Jan 20, 2020 at 6:31 PM Sam Guo <<a href="mailto:sam.guo@cd-adapco.com">sam.guo@cd-adapco.com</a>> wrote:<br>
> > I mean MatDestroy.<br>
> > <br>
> > On Mon, Jan 20, 2020 at 3:28 PM Sam Guo <<a href="mailto:sam.guo@cd-adapco.com">sam.guo@cd-adapco.com</a>> wrote:<br>
> > Does it hurt to call Destroy function without calling CreateFunction? For example <br>
> > Mat A, B;<br>
> > PetscErrorCode ierr1, ierr2;<br>
> > ierr1 = MatCreate(PETSC_COMM_WORLD,&A)<wbr>;<br>
> > if(ierr1 == 0)<br>
> > {<br>
> > ierr2 = MatCreate(PETSC_COMM_WORLD<br>
> > ,&B);<br>
> > <br>
> > }<br>
> > if(ierr1 !=0 || ierr2 != 0)<br>
> > {<br>
> > Destroy(&A);<br>
> > Destroy(&B); // if ierr1 !=0, MatCreat is not called on B. Does it hurt to call Destroy B here?<br>
> > }<br>
> > <br>
> > <br>
> > <br>
> > On Mon, Jan 20, 2020 at 11:11 AM Dave May <<a href="mailto:dave.mayhem23@gmail.com">dave.mayhem23@gmail.com</a>> wrote:<br>
> > <br>
> > <br>
> > On Mon 20. Jan 2020 at 19:47, Sam Guo <<a href="mailto:sam.guo@cd-adapco.com">sam.guo@cd-adapco.com</a>> wrote:<br>
> > Can I assume if there is MatCreat or VecCreate, I should clean up the memory myself?<br>
> > <br>
> > Yes. You will need to call the matching Destroy function.<br>
> > <br>
> > <br>
> > <br>
> > On Mon, Jan 20, 2020 at 10:45 AM Sam Guo <<a href="mailto:sam.guo@cd-adapco.com">sam.guo@cd-adapco.com</a>> wrote:<br>
> > I only include the first few lines of SLEPc example. What about following<br>
> > ierr = MatCreate(PETSC_COMM_WORLD,&A)<wbr>;CHKERRQ(ierr); <br>
> > ierr = MatSetSizes(A,PETSC_DECIDE,<wbr>PETSC_DECIDE,n,n);CHKERRQ(<wbr>ierr); <br>
> > Is there any memory lost?<br>
> > <br>
> > On Mon, Jan 20, 2020 at 10:41 AM Dave May <<a href="mailto:dave.mayhem23@gmail.com">dave.mayhem23@gmail.com</a>> wrote:<br>
> > <br>
> > <br>
> > On Mon 20. Jan 2020 at 19:39, Sam Guo <<a href="mailto:sam.guo@cd-adapco.com">sam.guo@cd-adapco.com</a>> wrote:<br>
> > 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,<br>
> > Mat A; /* problem matrix */ <br>
> > EPS eps; /* eigenproblem solver context */ <br>
> > EPSType type; <br>
> > PetscReal error,tol,re,im; <br>
> > PetscScalar kr,ki; Vec xr,xi; 25 <br>
> > PetscInt n=30,i,Istart,Iend,nev,maxit,<wbr>its,nconv; <br>
> > PetscErrorCode ierr; <br>
> > ierr = SlepcInitialize(&argc,&argv,(<wbr>char*)0,help);CHKERRQ(ierr); <br>
> > ierr = PetscOptionsGetInt(NULL,NULL,"<wbr>-n",&n,NULL);CHKERRQ(ierr);<br>
> > ierr = PetscPrintf(PETSC_COMM_WORLD,"<wbr>\n1-D Laplacian Eigenproblem, n=%D\n\n",n);CHKERRQ(ierr); <br>
> > <br>
> > I am wondering if the memory is lost by calling CHKERRQ.<br>
> > <br>
> > No.<br>
> > <br>
> > <br>
> > <br>
> > On Mon, Jan 20, 2020 at 10:14 AM Dave May <<a href="mailto:dave.mayhem23@gmail.com">dave.mayhem23@gmail.com</a>> wrote:<br>
> > <br>
> > <br>
> > On Mon 20. Jan 2020 at 19:11, Sam Guo <<a href="mailto:sam.guo@cd-adapco.com">sam.guo@cd-adapco.com</a>> wrote:<br>
> > Dear PETSc dev team,<br>
> > If PETSc function returns an error, what's the correct way to clean PETSc?<br>
> > <br>
> > The answer depends on the error message reported. Send the complete error message and a better answer can be provided.<br>
> > <br>
> > Particularly how to clean up the memory?<br>
> > <br>
> > Totally depends on the objects which aren’t being freed. You need to provide more information<br>
> > <br>
> > Thanks<br>
> > Dave<br>
> > <br>
> > <br>
> > Thanks,<br>
> > Sam<br>
> > <br>
> > <br>
> > -- <br>
> > 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<br>
> > <br>
> > <a href="https://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~<wbr>knepley/</a><br>
> <br>
<br>
</blockquote>