#ifdef DEAL_II_WITH_PETSC
# ifdef DEAL_II_WITH_SLEPC
// Initialize SLEPc (with PETSc):
- ierr = SlepcInitialize(&argc, &argv, nullptr, nullptr);
+ finalize_petscslepc = SlepcInitializeCalled ? false : true;
+ ierr = SlepcInitialize(&argc, &argv, nullptr, nullptr);
AssertThrow(ierr == 0, SLEPcWrappers::SolverBase::ExcSLEPcError(ierr));
# else
// or just initialize PETSc alone:
- ierr = PetscInitialize(&argc, &argv, nullptr, nullptr);
+ finalize_petscslepc = PetscInitializeCalled ? false : true;
+ ierr = PetscInitialize(&argc, &argv, nullptr, nullptr);
AssertThrow(ierr == 0, ExcPETScError(ierr));
# endif
// 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) &&
- (PetscFinalizeCalled == PETSC_FALSE))
+ if (!PetscFinalizeCalled)
{
GrowingVectorMemory<
PETScWrappers::MPI::Vector>::release_unused_memory();
GrowingVectorMemory<
PETScWrappers::MPI::BlockVector>::release_unused_memory();
-
+ }
# ifdef DEAL_II_WITH_SLEPC
- // and now end SLEPc (with PETSc)
- SlepcFinalize();
+ // and now end SLEPc with PETSc if we did so
+ if (finalize_petscslepc)
+ SlepcFinalize();
# else
- // or just end PETSc.
- PetscFinalize();
+ // or just end PETSc if we did so
+ if (finalize_petscslepc)
+ PetscFinalize();
# endif
- }
#endif
// There is a similar issue with CUDA: The destructor of static objects might