From 15204b8e78df9d82960c20c4ed057f41fb3ba4f4 Mon Sep 17 00:00:00 2001 From: bangerth Date: Mon, 7 Jan 2013 20:58:03 +0000 Subject: [PATCH] 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 --- deal.II/source/base/mpi.cc | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) 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 -- 2.39.5