From bd43ad00a42dc00000e18e7f0a0d1945fcacb6bf Mon Sep 17 00:00:00 2001 From: heister Date: Mon, 5 Aug 2013 22:02:32 +0000 Subject: [PATCH] check for PETSc memory leaks We are leaking in many tests, actually. git-svn-id: https://svn.dealii.org/trunk@30228 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/tests.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/tests.h b/tests/tests.h index 5234e5d7e4..a68e539790 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -32,6 +32,41 @@ #include #include + +#ifdef DEAL_II_WITH_PETSC +#include + +inline void check_petsc_allocations() +{ + PetscStageLog stageLog; + PetscLogGetStageLog(&stageLog); + + // I don't quite understand petsc and it looks like stageLog->stageInfo->classLog->classInfo[i].id + // is always -1, so we look it up in stageLog->classLog, make sure it has the same number of entries: + Assert(stageLog->stageInfo->classLog->numClasses == stageLog->classLog->numClasses, dealii::ExcInternalError()); + + bool errors = false; + for (int i=0;istageInfo->classLog->numClasses;++i) + { + if (stageLog->stageInfo->classLog->classInfo[i].destructions + != stageLog->stageInfo->classLog->classInfo[i].creations) + { + errors = true; + cerr << "ERROR: PETSc objects leaking of type '" + << stageLog->classLog->classInfo[i].name << "'" + << " with " << stageLog->stageInfo->classLog->classInfo[i].creations + << " creations and only " + << stageLog->stageInfo->classLog->classInfo[i].destructions + << " destructions." << std::endl; + } + } + + if (errors) + throw dealii::ExcMessage("PETSc memory leak"); +} +#endif + + // implicitly use the deal.II namespace everywhere, without us having to say // so in each and every testcase using namespace dealii; @@ -136,6 +171,7 @@ public: unsigned int nproc = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD); deallog.pop(); + if (myid!=0) { deallog.detach(); @@ -144,6 +180,11 @@ public: MPI_Barrier(MPI_COMM_WORLD); +#ifdef DEAL_II_WITH_PETSC + check_petsc_allocations(); + MPI_Barrier(MPI_COMM_WORLD); +#endif + if (myid==0) { for (unsigned int i=1; i