[petsc-users] KSP and VecDestroy

Shiyuan gshy2014 at gmail.com
Fri Oct 7 19:48:11 CDT 2011


Hi,
   I want to track down an memory problem and have something I don't
understand.
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? Does it create
memory leak becase of that? Thanks.

    ierr=PetscLogStagePush(memoryWatch);CHKERRQ(ierr);
    MatGetVecs(*(pCSolverNeu->pK),&x0,&rhs);
VecDuplicate(x0,&(workVec[0]));VecDuplicate(x0,&(workVec[1]));
    VecSetRandom(x0,randomctx);
    VecCopy(x0,workVec[0]);
    MatMult(*(pMGDataVec[0]->pA),x0,rhs);

    ierr=KSPSolve(ksp,rhs, workVec[0]);CHKERRQ(ierr);

    ierr=VecDestroy(&x0);CHKERRQ(ierr);
    ierr=VecDestroy(&rhs);CHKERRQ(ierr);
    ierr=VecDestroy(&workVec[0]);CHKERRQ(ierr);
    ierr=VecDestroy(&workVec[1]);CHKERRQ(ierr);
    ierr=PetscLogStagePop();CHKERRQ(ierr);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20111007/c3d1f931/attachment.htm>


More information about the petsc-users mailing list