<br><br><div class="gmail_quote">On Fri, Oct 7, 2011 at 7:49 PM, Jed Brown <span dir="ltr"><<a href="mailto:jedbrown@mcs.anl.gov">jedbrown@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="gmail_quote"><div class="im">On Fri, Oct 7, 2011 at 19:48, Shiyuan <span dir="ltr"><<a href="mailto:gshy2014@gmail.com" target="_blank">gshy2014@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi, <br> I want to track down an memory problem and have something I don't understand. <br>In the following part, I create four vectors and destroy them. If I don't call KSPSolve, log tells me four Vec are created and four Vec are destroyed which I expect. But if I call KSPSolve, log tells me four Vec are created but only two are destroyed in that Stage? Does KSP refer the two vectors somewhere inside which make VecDestroy cannot destroy them?</blockquote>
<div><br></div></div><div>Yes</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"> Does it create memory leak becase of that?</blockquote>
<div><br></div></div><div>No, they are destroyed when you call KSPDestroy().</div><div class="im">
<div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"> Thanks. <br>
<br> ierr=PetscLogStagePush(memoryWatch);CHKERRQ(ierr);<br> MatGetVecs(*(pCSolverNeu->pK),&x0,&rhs); VecDuplicate(x0,&(workVec[0]));VecDuplicate(x0,&(workVec[1]));<br> VecSetRandom(x0,randomctx); <br>
VecCopy(x0,workVec[0]);<br> MatMult(*(pMGDataVec[0]->pA),x0,rhs);<br> <br> ierr=KSPSolve(ksp,rhs, workVec[0]);CHKERRQ(ierr);<br> <br> ierr=VecDestroy(&x0);CHKERRQ(ierr);<br> ierr=VecDestroy(&rhs);CHKERRQ(ierr);<br>
ierr=VecDestroy(&workVec[0]);CHKERRQ(ierr);<br> ierr=VecDestroy(&workVec[1]);CHKERRQ(ierr);<br> ierr=PetscLogStagePop();CHKERRQ(ierr);<br>
</blockquote></div></div><br>
</blockquote></div>But in the -log_summary, these two Vecs seems not be counted as destroyed, which makes the number of created Vec is two more than the number of destroyed Vec. This makes me think that I forget to free memory. Is it supposed to work that way? Is the memory part in the log meant to be a way to detect the memory leak problem? Thanks. <br>