<div dir="ltr">Does it hurt to call Destroy function without calling CreateFunction? For example <div>Mat A, B;</div><div><pre width="80" style="color:rgb(0,0,0)"><a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscErrorCode.html#PetscErrorCode">PetscErrorCode</a> ierr1, ierr2;</pre></div><div><pre width="80" style="color:rgb(0,0,0)">ierr1 = <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreate.html#MatCreate">MatCreate</a>(<a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PETSC_COMM_WORLD.html#PETSC_COMM_WORLD">PETSC_COMM_WORLD</a>,&A);</pre><pre width="80" style="color:rgb(0,0,0)">if(ierr1 == 0)</pre><pre width="80" style="color:rgb(0,0,0)">{</pre><pre width="80" style="color:rgb(0,0,0)"> ierr2 = <a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreate.html#MatCreate" style="font-family:Arial,Helvetica,sans-serif">MatCreate</a><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">(</span><a href="https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PETSC_COMM_WORLD.html#PETSC_COMM_WORLD" style="font-family:Arial,Helvetica,sans-serif">PETSC_COMM_WORLD</a><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">,&B);
</span></pre><pre width="80" style="color:rgb(0,0,0)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">}</span></pre><pre width="80" style="color:rgb(0,0,0)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">if(ierr1 !=0 || ierr2 != 0)</span></pre><pre width="80" style="color:rgb(0,0,0)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">{</span></pre><pre width="80" style="color:rgb(0,0,0)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)"> Destroy(&A);</span></pre><pre width="80" style="color:rgb(0,0,0)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)"> Destroy(&B); // if ierr1 !=0, MatCreat is not called on B. Does it hurt to call Destroy B here?</span></pre><pre width="80" style="color:rgb(0,0,0)"><span style="font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">}</span></pre><pre width="80" style="color:rgb(0,0,0)"><br></pre></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">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></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><br></div><div><br><div class="gmail_quote"><div dir="ltr">On Mon 20. Jan 2020 at 19:47, Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.com</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 dir="ltr">Can I assume if there is MatCreat or VecCreate, I should clean up the memory myself?</div></blockquote><div dir="auto"><br></div><div dir="auto">Yes. You will need to call the matching Destroy function.</div><div dir="auto"><br></div><div dir="auto"><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 dir="ltr"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 20, 2020 at 10:45 AM Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.com</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 dir="ltr">I only include the first few lines of SLEPc example. What about following<div> ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr); </div><div> ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n);CHKERRQ(ierr); <br></div><div>Is there any memory lost?<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 20, 2020 at 10:41 AM Dave May <<a href="mailto:dave.mayhem23@gmail.com" target="_blank">dave.mayhem23@gmail.com</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><br></div><div><br><div class="gmail_quote"><div dir="ltr">On Mon 20. Jan 2020 at 19:39, Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.com</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 dir="ltr">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,<div>
Mat A; /* problem matrix */ </div><div> EPS eps; /* eigenproblem solver context */ </div><div> EPSType type; </div><div> PetscReal error,tol,re,im; </div><div> PetscScalar kr,ki;
Vec xr,xi;
25 </div><div> PetscInt n=30,i,Istart,Iend,nev,maxit,its,nconv; </div><div> PetscErrorCode ierr; </div><div> ierr = SlepcInitialize(&argc,&argv,(char*)0,help);CHKERRQ(ierr); </div><div> ierr = PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);CHKERRQ(ierr);</div><div> ierr = PetscPrintf(PETSC_COMM_WORLD,"\n1-D Laplacian Eigenproblem, n=%D\n\n",n);CHKERRQ(ierr); </div><div><br></div><div>I am wondering if the memory is lost by calling CHKERRQ.</div></div></blockquote><div dir="auto"><br></div><div dir="auto">No.</div><div dir="auto"><br></div><div dir="auto"><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 dir="ltr"><div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 20, 2020 at 10:14 AM Dave May <<a href="mailto:dave.mayhem23@gmail.com" target="_blank">dave.mayhem23@gmail.com</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><br></div><div><br><div class="gmail_quote"><div dir="ltr">On Mon 20. Jan 2020 at 19:11, Sam Guo <<a href="mailto:sam.guo@cd-adapco.com" target="_blank">sam.guo@cd-adapco.com</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 dir="ltr">Dear PETSc dev team,<div> If PETSc function returns an error, what's the correct way to clean PETSc? </div></div></blockquote><div dir="auto"><br></div><div dir="auto">The answer depends on the error message reported. Send the complete error message and a better answer can be provided.</div><div dir="auto"><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 dir="ltr"><div>Particularly how to clean up the memory?</div></div></blockquote><div dir="auto"><br></div><div dir="auto">Totally depends on the objects which aren’t being freed. You need to provide more information</div><div dir="auto"><br></div><div dir="auto">Thanks</div><div dir="auto">Dave</div><div dir="auto"><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 dir="ltr"><div></div><div><br></div><div>Thanks,</div><div>Sam</div></div>
</blockquote></div></div>
</blockquote></div>
</blockquote></div></div>
</blockquote></div>
</blockquote></div>
</blockquote></div></div>
</blockquote></div>