From 8d26f335aa8c3719b933cdec8036348ad2cea3c1 Mon Sep 17 00:00:00 2001 From: heister Date: Wed, 27 Mar 2013 03:31:17 +0000 Subject: [PATCH] make MPI_InitFinalize initialize PETSc even if not using MPI git-svn-id: https://svn.dealii.org/trunk@29052 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 7 +++++++ deal.II/source/base/mpi.cc | 36 ++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 4115f219e3..72a1f90da4 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -80,6 +80,13 @@ this function.
    +
  1. New: MPI_InitFinalize can also initialize PETSc/Slepc when +not compiling with MPI. This is now the preferred way to initialize +MPI/PETSc/Slepc in all cases. +
    +(Timo Heister, 2013/3/26) +
  2. +
  3. Added/fixed: IterativeInverse::vmult() can now handle vectors using a different number type than the matrix type. As usual, the number types must be compatible. Addtitionally, the initial guess is diff --git a/deal.II/source/base/mpi.cc b/deal.II/source/base/mpi.cc index edc8c03da9..4a1c99c7bb 100644 --- a/deal.II/source/base/mpi.cc +++ b/deal.II/source/base/mpi.cc @@ -338,9 +338,6 @@ namespace Utilities ExcMessage ("You can only create a single object of this class " "in a program since it initializes the MPI system.")); -#ifdef DEAL_II_WITH_MPI - // if we have PETSc, we will initialize it and let it handle MPI. - // Otherwise, we will do it. #ifdef DEAL_II_WITH_PETSC # ifdef DEAL_II_WITH_SLEPC // Initialise SLEPc (with PETSc): @@ -350,6 +347,9 @@ namespace Utilities PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL); # endif #else +# ifdef DEAL_II_WITH_MPI + // if we have PETSc, we will initialize it and let it handle MPI. + // Otherwise, we will do it. int MPI_has_been_started = 0; MPI_Initialized(&MPI_has_been_started); AssertThrow (MPI_has_been_started == 0, @@ -359,13 +359,13 @@ namespace Utilities mpi_err = MPI_Init (&argc, &argv); AssertThrow (mpi_err == 0, ExcMessage ("MPI could not be initialized.")); -#endif -#else +# else // make sure the compiler doesn't warn // about these variables (void)argc; (void)argv; (void)owns_mpi; +# endif #endif constructor_has_already_run = true; @@ -377,26 +377,26 @@ namespace Utilities MPI_InitFinalize::~MPI_InitFinalize() { -#ifdef DEAL_II_WITH_MPI - - // make memory pool release all MPI-based vectors that are no + // make memory pool release all PETSc/Trilinos/MPI-based vectors that are no // longer used at this point. this is relevant because the // static object destructors run for these vectors at the end of // the program would run after MPI_Finalize is called, leading // to errors + +#ifdef DEAL_II_WITH_MPI + // Start with Trilinos (need to do this before finalizing PETSc because it finalizes MPI. + // Delete vectors from the pools: # if defined(DEAL_II_WITH_TRILINOS) GrowingVectorMemory ::release_unused_memory (); GrowingVectorMemory ::release_unused_memory (); # endif +#endif - // 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 + + // Now deal with PETSc (with or without MPI). Only delete the vectors if finalize hasn't + // been called yet, otherwise this will lead to errors. #ifdef DEAL_II_WITH_PETSC if ((PetscInitializeCalled == PETSC_TRUE) && @@ -418,10 +418,14 @@ namespace Utilities // or just end PETSc. PetscFinalize(); # endif - } -#else + } +#endif + // only MPI_Finalize if we are running with MPI and we are not using PETSc + // (otherwise we called it above already): +#ifdef DEAL_II_WITH_MPI +#ifndef DEAL_II_WITH_PETSC int mpi_err = 0; int MPI_has_been_started = 0; -- 2.39.5