]> https://gitweb.dealii.org/ - dealii.git/commitdiff
PETScWrappers: Support with-strict-petscerrorcode configurations 15768/head
authorStefano Zampini <stefano.zampini@gmail.com>
Wed, 19 Jul 2023 17:17:51 +0000 (19:17 +0200)
committerStefano Zampini <stefano.zampini@gmail.com>
Wed, 19 Jul 2023 18:04:50 +0000 (20:04 +0200)
SNES and TS intentionally left out since those changes  will be in separate commits

include/deal.II/lac/petsc_compatibility.h
source/base/mpi.cc
source/lac/exceptions.cc
source/lac/petsc_matrix_base.cc
source/lac/petsc_precondition.cc
source/lac/petsc_solver.cc
tests/tests.h

index e1e2cbc6664a2bd6416143af6c067db2ebd4ac88..449f68190fb010263600ce0ae607ead86f33147a 100644 (file)
 
 #ifdef DEAL_II_WITH_PETSC
 
-#  include <petscconf.h>
 #  include <petscksp.h>
 #  include <petscmat.h>
 #  include <petscpc.h>
 #  include <petscsnes.h>
 #  include <petscts.h>
+#  if DEAL_II_PETSC_VERSION_LT(3, 19, 0)
+#    define PETSC_SUCCESS 0
+#  endif
 
 #  include <string>
 
index 04f7af7fa9150f386c5f4786f30d64bf77e6759c..0663721d447f9aee3e8d5feba7785dcd9aea0bc5 100644 (file)
@@ -818,21 +818,23 @@ namespace Utilities
       // we are allowed to call MPI_Init ourselves and PETScInitialize will
       // detect this. This allows us to use MPI_Init_thread instead.
 #ifdef DEAL_II_WITH_PETSC
+      PetscErrorCode pierr;
 #  ifdef DEAL_II_WITH_SLEPC
       // Initialize SLEPc (with PETSc):
       finalize_petscslepc = SlepcInitializeCalled ? false : true;
-      ierr                = SlepcInitialize(&argc, &argv, nullptr, nullptr);
-      AssertThrow(ierr == 0, SLEPcWrappers::SolverBase::ExcSLEPcError(ierr));
+      pierr               = SlepcInitialize(&argc, &argv, nullptr, nullptr);
+      AssertThrow(pierr == 0, SLEPcWrappers::SolverBase::ExcSLEPcError(pierr));
 #  else
       // or just initialize PETSc alone:
       finalize_petscslepc = PetscInitializeCalled ? false : true;
-      ierr                = PetscInitialize(&argc, &argv, nullptr, nullptr);
-      AssertThrow(ierr == 0, ExcPETScError(ierr));
+      pierr               = PetscInitialize(&argc, &argv, nullptr, nullptr);
+      AssertThrow(pierr == 0, ExcPETScError(pierr));
 #  endif
 
       // Disable PETSc exception handling. This just prints a large wall
       // of text that is not particularly helpful for what we do:
-      PetscPopSignalHandler();
+      pierr = PetscPopSignalHandler();
+      AssertThrow(pierr == 0, ExcPETScError(pierr));
 #endif
 
       // Initialize zoltan
@@ -1014,11 +1016,17 @@ namespace Utilities
 #  ifdef DEAL_II_WITH_SLEPC
       // and now end SLEPc with PETSc if we did so
       if (finalize_petscslepc)
-        SlepcFinalize();
+        {
+          PetscErrorCode ierr = SlepcFinalize();
+          AssertThrow(ierr == 0, SLEPcWrappers::SolverBase::ExcSLEPcError(ierr))
+        }
 #  else
       // or just end PETSc if we did so
       if (finalize_petscslepc)
-        PetscFinalize();
+        {
+          PetscErrorCode ierr = PetscFinalize();
+          AssertThrow(ierr == 0, ExcPETScError(ierr));
+        }
 #  endif
 #endif
 
index c17a1db790abda3b458556d62d7f0f4b90b854ec..a1de99319b5dd9abfa9d0fc5e25a90508ced7642 100644 (file)
@@ -18,7 +18,6 @@
 #include <deal.II/lac/exceptions.h>
 
 #ifdef DEAL_II_WITH_PETSC
-#  include <petscconf.h>
 #  include <petscsys.h>
 #endif // DEAL_II_WITH_PETSC
 
@@ -39,9 +38,10 @@ namespace LACExceptions
     // PetscErrorMessage changes the value in a pointer to refer to a
     // statically allocated description of the current error message.
     const char *         petsc_message;
-    const PetscErrorCode ierr = PetscErrorMessage(error_code,
-                                                  &petsc_message,
-                                                  /*specific=*/nullptr);
+    const PetscErrorCode ierr =
+      PetscErrorMessage(static_cast<PetscErrorCode>(error_code),
+                        &petsc_message,
+                        /*specific=*/nullptr);
     if (ierr == 0 && petsc_message != nullptr)
       {
         out << "The description of the error provided by PETSc is \""
index 163d2f3bc585eaa0db71bbfecd1b89fd506856c0..2949542d663745ce7f53e34499ca2368d1a3587b 100644 (file)
@@ -168,16 +168,18 @@ namespace PETScWrappers
     // since this is a collective operation
     IS index_set;
 
-    ISCreateGeneral(get_mpi_communicator(),
-                    rows.size(),
-                    petsc_rows.data(),
-                    PETSC_COPY_VALUES,
-                    &index_set);
+    PetscErrorCode ierr;
+    ierr = ISCreateGeneral(get_mpi_communicator(),
+                           rows.size(),
+                           petsc_rows.data(),
+                           PETSC_COPY_VALUES,
+                           &index_set);
+    AssertThrow(ierr == 0, ExcPETScError(ierr));
 
-    const PetscErrorCode ierr =
-      MatZeroRowsIS(matrix, index_set, new_diag_value, nullptr, nullptr);
+    ierr = MatZeroRowsIS(matrix, index_set, new_diag_value, nullptr, nullptr);
+    AssertThrow(ierr == 0, ExcPETScError(ierr));
+    ierr = ISDestroy(&index_set);
     AssertThrow(ierr == 0, ExcPETScError(ierr));
-    ISDestroy(&index_set);
   }
 
   void
@@ -195,16 +197,19 @@ namespace PETScWrappers
     // since this is a collective operation
     IS index_set;
 
-    ISCreateGeneral(get_mpi_communicator(),
-                    rows.size(),
-                    petsc_rows.data(),
-                    PETSC_COPY_VALUES,
-                    &index_set);
+    PetscErrorCode ierr;
+    ierr = ISCreateGeneral(get_mpi_communicator(),
+                           rows.size(),
+                           petsc_rows.data(),
+                           PETSC_COPY_VALUES,
+                           &index_set);
+    AssertThrow(ierr == 0, ExcPETScError(ierr));
 
-    const PetscErrorCode ierr =
+    ierr =
       MatZeroRowsColumnsIS(matrix, index_set, new_diag_value, nullptr, nullptr);
     AssertThrow(ierr == 0, ExcPETScError(ierr));
-    ISDestroy(&index_set);
+    ierr = ISDestroy(&index_set);
+    AssertThrow(ierr == 0, ExcPETScError(ierr));
   }
 
 
index 2e51d0cdfe29b6c9876e0ed02bc6d677d4f32dc8..e7f221de42e6aee522811e420a3b06468970ee25 100644 (file)
@@ -1114,7 +1114,7 @@ namespace PETScWrappers
     // interface code of PCSetUp in PETSc.
     // We handle it here.
     PetscCall(pc_set_failed_reason(ppc, PC_NOERROR));
-    PetscFunctionReturn(0);
+    PetscFunctionReturn(PETSC_SUCCESS);
   }
 
   PetscErrorCode
@@ -1155,7 +1155,7 @@ namespace PETScWrappers
           "Failure in pcapply from dealii::PETScWrappers::NonlinearSolver");
       }
     petsc_increment_state_counter(y);
-    PetscFunctionReturn(0);
+    PetscFunctionReturn(PETSC_SUCCESS);
   }
 
   PetscErrorCode
@@ -1196,7 +1196,7 @@ namespace PETScWrappers
           "Failure in pcapply_transpose from dealii::PETScWrappers::NonlinearSolver");
       }
     petsc_increment_state_counter(y);
-    PetscFunctionReturn(0);
+    PetscFunctionReturn(PETSC_SUCCESS);
   }
 
 
index d5b8b2f37e30c8ca45bee20e55c53852923c5844..7b9308fefded336d6d76119f3d103dd6e0091a8a 100644 (file)
@@ -163,13 +163,14 @@ namespace PETScWrappers
   }
 
 
-  int
+  PetscErrorCode
   SolverBase::convergence_test(KSP /*ksp*/,
                                const PetscInt      iteration,
                                const PetscReal     residual_norm,
                                KSPConvergedReason *reason,
                                void *              solver_control_x)
   {
+    PetscFunctionBeginUser;
     SolverControl &solver_control =
       *reinterpret_cast<SolverControl *>(solver_control_x);
 
@@ -197,8 +198,7 @@ namespace PETScWrappers
           Assert(false, ExcNotImplemented());
       }
 
-    // return without failure
-    return 0;
+    PetscFunctionReturn(PETSC_SUCCESS);
   }
 
 
index c9575230dd65e6c32d42cc3166410b6c7ad613c5..0fa6bf2eea12fb11164ae7a1e42f059ff808ef91 100644 (file)
@@ -461,8 +461,11 @@ namespace
   void
   check_petsc_allocations()
   {
-    PetscStageLog stageLog;
-    PetscLogGetStageLog(&stageLog);
+    PetscStageLog  stageLog;
+    PetscErrorCode ierr;
+
+    ierr = PetscLogGetStageLog(&stageLog);
+    AssertThrow(ierr == 0, ExcPETScError(ierr));
 
     // I don't quite understand petsc and it looks like
     // stageLog->stageInfo->classLog->classInfo[i].id is always -1, so we look

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.