From: bangerth Date: Mon, 7 Jan 2013 20:58:03 +0000 (+0000) Subject: Only clean up memory if PETSc hasn't done that itself yet. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15204b8e78df9d82960c20c4ed057f41fb3ba4f4;p=dealii-svn.git Only clean up memory if PETSc hasn't done that itself yet. git-svn-id: https://svn.dealii.org/trunk@27968 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/source/base/mpi.cc b/deal.II/source/base/mpi.cc index 4ad632d348..0f0b14b717 100644 --- a/deal.II/source/base/mpi.cc +++ b/deal.II/source/base/mpi.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2005, 2006, 2008, 2009, 2010, 2011, 2012 by the deal.II authors +// Copyright (C) 2005, 2006, 2008, 2009, 2010, 2011, 2012, 2013 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -367,23 +367,33 @@ namespace Utilities ::release_unused_memory (); # endif - // Same for PETSc. + // Same for PETSc. only do this if PETSc hasn't been + // terminated yet since PETSc deletes all vectors that + // have been allocated but not freed at the time of + // calling PETScFinalize. running the calls below after + // PetscFinalize has already been called will therefore + // yield errors of double deallocations #ifdef DEAL_II_USE_PETSC - GrowingVectorMemory - ::release_unused_memory (); - GrowingVectorMemory - ::release_unused_memory (); - GrowingVectorMemory - ::release_unused_memory (); - GrowingVectorMemory - ::release_unused_memory (); + if ((PetscInitializeCalled == PETSC_TRUE) + && + (PetscFinalizeCalled == PETSC_FALSE)) + { + GrowingVectorMemory + ::release_unused_memory (); + GrowingVectorMemory + ::release_unused_memory (); + GrowingVectorMemory + ::release_unused_memory (); + GrowingVectorMemory + ::release_unused_memory (); # ifdef DEAL_II_USE_SLEPC - // and now end SLEPc (with PETSc) - SlepcFinalize(); + // and now end SLEPc (with PETSc) + SlepcFinalize(); # else - // or just end PETSc. - PetscFinalize(); + // or just end PETSc. + PetscFinalize(); + } # endif #else