From: David Wells Date: Thu, 17 Nov 2016 00:42:36 +0000 (-0500) Subject: Consistently check PETSc/SLEPc error codes. X-Git-Tag: v8.5.0-rc1~382^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=070d3f174c8f17d3f1d39377cfdc0d543e3541e8;p=dealii.git Consistently check PETSc/SLEPc error codes. --- diff --git a/source/base/mpi.cc b/source/base/mpi.cc index 6ddcd0d52b..b1c770a8a8 100644 --- a/source/base/mpi.cc +++ b/source/base/mpi.cc @@ -48,6 +48,7 @@ # ifdef DEAL_II_WITH_MPI # include # endif +# include #endif #ifdef DEAL_II_WITH_P4EST @@ -357,10 +358,12 @@ namespace Utilities #ifdef DEAL_II_WITH_PETSC # ifdef DEAL_II_WITH_SLEPC // Initialize SLEPc (with PETSc): - SlepcInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL); + ierr = SlepcInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL); + AssertThrow (ierr == 0, SLEPcWrappers::SolverBase::ExcSLEPcError(ierr)); # else // or just initialize PETSc alone: - PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL); + ierr = PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL); + AssertThrow (ierr == 0, ExcPETScError(ierr)); # endif #endif diff --git a/source/lac/petsc_matrix_base.cc b/source/lac/petsc_matrix_base.cc index a94467b6c6..38612fb576 100644 --- a/source/lac/petsc_matrix_base.cc +++ b/source/lac/petsc_matrix_base.cc @@ -561,11 +561,13 @@ namespace PETScWrappers assert_is_compressed (); // Set options - PetscViewerSetFormat (PETSC_VIEWER_STDOUT_WORLD, - format); + int ierr = PetscViewerSetFormat (PETSC_VIEWER_STDOUT_WORLD, + format); + AssertThrow (ierr == 0, ExcPETScError(ierr)); // Write to screen - MatView (matrix, PETSC_VIEWER_STDOUT_WORLD); + ierr = MatView (matrix, PETSC_VIEWER_STDOUT_WORLD); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } void @@ -603,7 +605,8 @@ namespace PETScWrappers MatrixBase::memory_consumption() const { MatInfo info; - MatGetInfo(matrix, MAT_LOCAL, &info); + const int ierr = MatGetInfo(matrix, MAT_LOCAL, &info); + AssertThrow (ierr == 0, ExcPETScError(ierr)); return sizeof(*this) + static_cast(info.memory); } diff --git a/source/lac/petsc_parallel_sparse_matrix.cc b/source/lac/petsc_parallel_sparse_matrix.cc index 9489b8b5d6..0444cb1e75 100644 --- a/source/lac/petsc_parallel_sparse_matrix.cc +++ b/source/lac/petsc_parallel_sparse_matrix.cc @@ -660,10 +660,11 @@ namespace PETScWrappers for (size_type i=local_row_start; i(PCICC)); + int ierr = PCSetType (pc, const_cast(PCICC)); AssertThrow (ierr == 0, ExcPETScError(ierr)); // then set flags - PCFactorSetLevels (pc, additional_data.levels); + ierr = PCFactorSetLevels (pc, additional_data.levels); AssertThrow (ierr == 0, ExcPETScError(ierr)); ierr = PCSetFromOptions (pc); @@ -445,7 +444,7 @@ namespace PETScWrappers AssertThrow (ierr == 0, ExcPETScError(ierr)); // then set flags - PCFactorSetLevels (pc, additional_data.levels); + ierr = PCFactorSetLevels (pc, additional_data.levels); AssertThrow (ierr == 0, ExcPETScError(ierr)); ierr = PCSetFromOptions (pc); diff --git a/source/lac/petsc_solver.cc b/source/lac/petsc_solver.cc index a6107b6b84..4c14576643 100644 --- a/source/lac/petsc_solver.cc +++ b/source/lac/petsc_solver.cc @@ -110,9 +110,10 @@ namespace PETScWrappers // checks with the solver_control // object we have in this object for // convergence - KSPSetConvergenceTest (solver_data->ksp, &convergence_test, - reinterpret_cast(&solver_control), - PETSC_NULL); + ierr = KSPSetConvergenceTest (solver_data->ksp, &convergence_test, + reinterpret_cast(&solver_control), + PETSC_NULL); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } // set the command line option prefix name @@ -227,9 +228,10 @@ namespace PETScWrappers // checks with the solver_control // object we have in this object for // convergence - KSPSetConvergenceTest (solver_data->ksp, &convergence_test, - reinterpret_cast(&solver_control), - PETSC_NULL); + ierr = KSPSetConvergenceTest (solver_data->ksp, &convergence_test, + reinterpret_cast(&solver_control), + PETSC_NULL); + AssertThrow (ierr == 0, ExcPETScError(ierr)); // set the command line options provided // by the user to override the defaults @@ -272,7 +274,8 @@ namespace PETScWrappers // in the deal.II solvers, we always // honor the initial guess in the // solution vector. do so here as well: - KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + ierr = KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + AssertThrow (ierr == 0, ExcPETScError(ierr)); // Hand over the absolute // tolerance and the maximum @@ -287,8 +290,9 @@ namespace PETScWrappers // the Richardson iteration, // where no residual is // available. - KSPSetTolerances(ksp, PETSC_DEFAULT, this->solver_control.tolerance(), - PETSC_DEFAULT, this->solver_control.max_steps()+1); + ierr = KSPSetTolerances(ksp, PETSC_DEFAULT, this->solver_control.tolerance(), + PETSC_DEFAULT, this->solver_control.max_steps()+1); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } @@ -320,7 +324,8 @@ namespace PETScWrappers // in the deal.II solvers, we always // honor the initial guess in the // solution vector. do so here as well: - KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + ierr = KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } @@ -344,7 +349,8 @@ namespace PETScWrappers // in the deal.II solvers, we always // honor the initial guess in the // solution vector. do so here as well: - KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + ierr = KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } @@ -368,7 +374,8 @@ namespace PETScWrappers // in the deal.II solvers, we always // honor the initial guess in the // solution vector. do so here as well: - KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + ierr = KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } @@ -444,7 +451,8 @@ namespace PETScWrappers // in the deal.II solvers, we always // honor the initial guess in the // solution vector. do so here as well: - KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + ierr = KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } @@ -468,7 +476,8 @@ namespace PETScWrappers // in the deal.II solvers, we always // honor the initial guess in the // solution vector. do so here as well: - KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + ierr = KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } @@ -492,7 +501,8 @@ namespace PETScWrappers // in the deal.II solvers, we always // honor the initial guess in the // solution vector. do so here as well: - KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + ierr = KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } @@ -510,14 +520,14 @@ namespace PETScWrappers void SolverTFQMR::set_solver_type (KSP &ksp) const { - int ierr; - ierr = KSPSetType (ksp, KSPTFQMR); + int ierr = KSPSetType (ksp, KSPTFQMR); AssertThrow (ierr == 0, ExcPETScError(ierr)); // in the deal.II solvers, we always // honor the initial guess in the // solution vector. do so here as well: - KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + ierr = KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } @@ -541,7 +551,8 @@ namespace PETScWrappers // in the deal.II solvers, we always // honor the initial guess in the // solution vector. do so here as well: - KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + ierr = KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } @@ -559,14 +570,14 @@ namespace PETScWrappers void SolverCR::set_solver_type (KSP &ksp) const { - int ierr; - ierr = KSPSetType (ksp, KSPCR); + int ierr = KSPSetType (ksp, KSPCR); AssertThrow (ierr == 0, ExcPETScError(ierr)); // in the deal.II solvers, we always // honor the initial guess in the // solution vector. do so here as well: - KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + ierr = KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } @@ -590,7 +601,8 @@ namespace PETScWrappers // in the deal.II solvers, we always // honor the initial guess in the // solution vector. do so here as well: - KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + ierr = KSPSetInitialGuessNonzero (ksp, PETSC_TRUE); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } @@ -608,8 +620,7 @@ namespace PETScWrappers void SolverPreOnly::set_solver_type (KSP &ksp) const { - int ierr; - ierr = KSPSetType (ksp, KSPPREONLY); + int ierr = KSPSetType (ksp, KSPPREONLY); AssertThrow (ierr == 0, ExcPETScError(ierr)); // The KSPPREONLY solver of @@ -625,7 +636,8 @@ namespace PETScWrappers // Using the PREONLY solver with // a nonzero initial guess leads // PETSc to produce some error messages. - KSPSetInitialGuessNonzero (ksp, PETSC_FALSE); + ierr = KSPSetInitialGuessNonzero (ksp, PETSC_FALSE); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } @@ -670,7 +682,8 @@ namespace PETScWrappers * Using a PREONLY solver with a nonzero initial guess leads PETSc to * produce some error messages. */ - KSPSetInitialGuessNonzero (ksp, PETSC_FALSE); + ierr = KSPSetInitialGuessNonzero (ksp, PETSC_FALSE); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } void @@ -752,9 +765,10 @@ namespace PETScWrappers * convergence monitor function that checks with the solver_control * object for convergence */ - KSPSetConvergenceTest (solver_data->ksp, &convergence_test, - reinterpret_cast(&solver_control), - PETSC_NULL); + ierr = KSPSetConvergenceTest (solver_data->ksp, &convergence_test, + reinterpret_cast(&solver_control), + PETSC_NULL); + AssertThrow (ierr == 0, ExcPETScError(ierr)); /** * set the software that is to be used to perform the lu diff --git a/source/lac/petsc_sparse_matrix.cc b/source/lac/petsc_sparse_matrix.cc index 7acf5e0644..d8eadb3953 100644 --- a/source/lac/petsc_sparse_matrix.cc +++ b/source/lac/petsc_sparse_matrix.cc @@ -129,7 +129,8 @@ namespace PETScWrappers SparseMatrix::get_mpi_communicator () const { static MPI_Comm comm; - PetscObjectGetComm((PetscObject)matrix, &comm); + const int ierr = PetscObjectGetComm((PetscObject)matrix, &comm); + AssertThrow (ierr == 0, ExcPETScError(ierr)); return comm; } @@ -229,9 +230,10 @@ namespace PETScWrappers row_entries[j] = sparsity_pattern.column_number (i,j); const PetscInt int_row = i; - MatSetValues (matrix, 1, &int_row, - row_lengths[i], &row_entries[0], - &row_values[0], INSERT_VALUES); + const int ierr = MatSetValues (matrix, 1, &int_row, + row_lengths[i], &row_entries[0], + &row_values[0], INSERT_VALUES); + AssertThrow (ierr == 0, ExcPETScError(ierr)); } compress (VectorOperation::insert); diff --git a/source/lac/petsc_vector_base.cc b/source/lac/petsc_vector_base.cc index 71a2e7e6ed..9a6390030c 100644 --- a/source/lac/petsc_vector_base.cc +++ b/source/lac/petsc_vector_base.cc @@ -1052,11 +1052,13 @@ namespace PETScWrappers //TODO[TH]:assert(is_compressed()) // Set options - PetscViewerSetFormat (PETSC_VIEWER_STDOUT_WORLD, - format); + int ierr = PetscViewerSetFormat (PETSC_VIEWER_STDOUT_WORLD, + format); + AssertThrow (ierr == 0, ExcPETScError(ierr)); // Write to screen - VecView (vector, PETSC_VIEWER_STDOUT_WORLD); + ierr = VecView (vector, PETSC_VIEWER_STDOUT_WORLD); + AssertThrow (ierr == 0, ExcPETScError(ierr)); }