<div dir="ltr">Dear Petsc developers,<div><br></div><div>I am trying to use Petsc with C++. And came across one issue. </div><div>Class DMManage has been defined, one default constructor and destructor has been defined there. </div><div>The code has a runtime error, "double free or corruption". Finally I found that, this is due to PetscFinalize. If I called explicitly the destructor before this PetscFinalze, the error will disappear. </div><div><br></div><div>Does that mean
PetscFinalize do some work to destroy DM? </div><div><br></div><div>Thanks, </div><div><br></div><div>#include <petscdmplex.h><br>#include <petscdmadaptor.h><br>#include <petscds.h><br>#include <petscviewerhdf5.h><br></div><div><br></div><div>class DMManage{<br> PetscSF distributionSF;<br>public: <br> DM dm;<br> DMManage();<br> ~DMManage();<br>};<br><br>DMManage::DMManage(){<br> const char filename[] = "ParallelWaveguide.msh";<br> DM dmDist;<br> PetscViewer viewer;<br> PetscViewerCreate(PETSC_COMM_WORLD, &viewer);<br> PetscViewerSetType(viewer, PETSCVIEWERASCII);<br> PetscViewerFileSetMode(viewer, FILE_MODE_READ);<br> PetscViewerFileSetName(viewer, filename);<br> DMPlexCreateGmsh(PETSC_COMM_WORLD, viewer, PETSC_TRUE, &dm);<br> PetscViewerDestroy(&viewer);<br> PetscInt overlap = 0;<br> DMPlexDistribute(dm, overlap, &distributionSF, &dmDist);<br> std::cout<<&dm<<std::endl;<br> if (dmDist) {<br> DMDestroy(&dm);<br> dm = dmDist;<br> }<br> DMDestroy(&dmDist);<br>}<br><br>DMManage::~DMManage(){<br> DMDestroy(&dm);<br>}<br><br>int main(int argc, char** argv) {<br> PetscFunctionBeginUser;<br> PetscCall(PetscInitialize(&argc, &argv, NULL, help));<br><br> DMManage objDMManage;<br><br> PetscFinalize();<br> return 0;<br>}<br></div></div>