]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Allow compilation with PETSc but without MPI. 15788/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Sat, 22 Jul 2023 18:08:49 +0000 (12:08 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Mon, 24 Jul 2023 17:32:43 +0000 (11:32 -0600)
source/lac/petsc_communication_pattern.cc

index 78d60402a348184f77a9ff847e1fc8be9e52ad84..c2eb6c87b6601e50c505b4439363aacccdbd7963 100644 (file)
@@ -37,11 +37,15 @@ namespace PETScWrappers
     : sf(nullptr)
   {}
 
+
+
   CommunicationPattern::~CommunicationPattern()
   {
     clear();
   }
 
+
+
   void
   CommunicationPattern::reinit(const types::global_dof_index local_size,
                                const IndexSet &              ghost_indices,
@@ -78,6 +82,8 @@ namespace PETScWrappers
     AssertPETSc(PetscLayoutDestroy(&layout));
   }
 
+
+
   void
   CommunicationPattern::reinit(const IndexSet &locally_owned_indices,
                                const IndexSet &ghost_indices,
@@ -96,6 +102,8 @@ namespace PETScWrappers
     this->do_reinit(in_petsc, dummy, out_petsc, dummy, communicator);
   }
 
+
+
   void
   CommunicationPattern::reinit(
     const std::vector<types::global_dof_index> &indices_has,
@@ -149,6 +157,8 @@ namespace PETScWrappers
                     communicator);
   }
 
+
+
   void
   CommunicationPattern::do_reinit(const std::vector<PetscInt> &inidx,
                                   const std::vector<PetscInt> &inloc,
@@ -243,50 +253,80 @@ namespace PETScWrappers
     AssertPETSc(PetscSFDestroy(&sf2));
   }
 
+
+
   void
   CommunicationPattern::clear()
   {
     AssertPETSc(PetscSFDestroy(&sf));
   }
 
+
+
   MPI_Comm
   CommunicationPattern::get_mpi_communicator() const
   {
     return PetscObjectComm(reinterpret_cast<PetscObject>(sf));
   }
 
+
+
   template <typename Number>
   void
   CommunicationPattern::export_to_ghosted_array_start(
     const ArrayView<const Number> &src,
     const ArrayView<Number> &      dst) const
   {
+#  ifdef DEAL_II_WITH_MPI
     auto datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
 
-#  if DEAL_II_PETSC_VERSION_LT(3, 15, 0)
+#    if DEAL_II_PETSC_VERSION_LT(3, 15, 0)
     AssertPETSc(PetscSFBcastBegin(sf, datatype, src.data(), dst.data()));
-#  else
+#    else
     AssertPETSc(
       PetscSFBcastBegin(sf, datatype, src.data(), dst.data(), MPI_REPLACE));
+#    endif
+
+#  else
+
+    (void)src;
+    (void)dst;
+    Assert(false,
+           ExcMessage("This program is running without MPI. There should "
+                      "not be anything to import or export!"));
 #  endif
   }
 
+
+
   template <typename Number>
   void
   CommunicationPattern::export_to_ghosted_array_finish(
     const ArrayView<const Number> &src,
     const ArrayView<Number> &      dst) const
   {
+#  ifdef DEAL_II_WITH_MPI
     auto datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
 
-#  if DEAL_II_PETSC_VERSION_LT(3, 15, 0)
+#    if DEAL_II_PETSC_VERSION_LT(3, 15, 0)
     AssertPETSc(PetscSFBcastEnd(sf, datatype, src.data(), dst.data()));
-#  else
+#    else
     AssertPETSc(
       PetscSFBcastEnd(sf, datatype, src.data(), dst.data(), MPI_REPLACE));
+#    endif
+
+#  else
+
+    (void)src;
+    (void)dst;
+    Assert(false,
+           ExcMessage("This program is running without MPI. There should "
+                      "not be anything to import or export!"));
 #  endif
   }
 
+
+
   template <typename Number>
   void
   CommunicationPattern::export_to_ghosted_array(
@@ -297,6 +337,8 @@ namespace PETScWrappers
     export_to_ghosted_array_finish(src, dst);
   }
 
+
+
   template <typename Number>
   void
   CommunicationPattern::import_from_ghosted_array_start(
@@ -304,13 +346,26 @@ namespace PETScWrappers
     const ArrayView<const Number> &src,
     const ArrayView<Number> &      dst) const
   {
+#  ifdef DEAL_II_WITH_MPI
     MPI_Op mpiop    = (op == VectorOperation::insert) ? MPI_REPLACE : MPI_SUM;
     auto   datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
 
     AssertPETSc(
       PetscSFReduceBegin(sf, datatype, src.data(), dst.data(), mpiop));
+
+#  else
+
+    (void)op;
+    (void)src;
+    (void)dst;
+    Assert(false,
+           ExcMessage("This program is running without MPI. There should "
+                      "not be anything to import or export!"));
+#  endif
   }
 
+
+
   template <typename Number>
   void
   CommunicationPattern::import_from_ghosted_array_finish(
@@ -318,12 +373,25 @@ namespace PETScWrappers
     const ArrayView<const Number> &src,
     const ArrayView<Number> &      dst) const
   {
+#  ifdef DEAL_II_WITH_MPI
     MPI_Op mpiop    = (op == VectorOperation::insert) ? MPI_REPLACE : MPI_SUM;
     auto   datatype = Utilities::MPI::mpi_type_id_for_type<Number>;
 
     AssertPETSc(PetscSFReduceEnd(sf, datatype, src.data(), dst.data(), mpiop));
+
+#  else
+
+    (void)op;
+    (void)src;
+    (void)dst;
+    Assert(false,
+           ExcMessage("This program is running without MPI. There should "
+                      "not be anything to import or export!"));
+#  endif
   }
 
+
+
   template <typename Number>
   void
   CommunicationPattern::import_from_ghosted_array(
@@ -335,6 +403,8 @@ namespace PETScWrappers
     import_from_ghosted_array_finish(op, src, dst);
   }
 
+
+
   // Partitioner
 
   Partitioner::Partitioner()
@@ -345,6 +415,8 @@ namespace PETScWrappers
     , n_ghost_indices_larger(numbers::invalid_dof_index)
   {}
 
+
+
   void
   Partitioner::reinit(const IndexSet &locally_owned_indices,
                       const IndexSet &ghost_indices,

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.