]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
check for PETSc memory leaks
authorheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 5 Aug 2013 22:02:32 +0000 (22:02 +0000)
committerheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 5 Aug 2013 22:02:32 +0000 (22:02 +0000)
We are leaking in many tests, actually.

git-svn-id: https://svn.dealii.org/trunk@30228 0785d39b-7218-0410-832d-ea1e28bc413d

tests/tests.h

index 5234e5d7e43d30bc094afbbf966b057e14e23790..a68e5397904334caffc00eabe4be318a8d16c439 100644 (file)
 #include <sstream>
 #include <iomanip>
 
+
+#ifdef DEAL_II_WITH_PETSC
+#include <petscsys.h>
+
+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;i<stageLog->stageInfo->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<nproc; ++i)

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.