#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;
unsigned int nproc = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD);
deallog.pop();
+
if (myid!=0)
{
deallog.detach();
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)