]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Choose to initialize ghost elements with reinit(partitioner). 14536/head
authorMarc Fehling <mafehling.git@gmail.com>
Fri, 2 Dec 2022 21:11:20 +0000 (14:11 -0700)
committerMarc Fehling <mafehling.git@gmail.com>
Mon, 5 Dec 2022 22:36:28 +0000 (15:36 -0700)
doc/news/changes/minor/20221205Fehling [new file with mode: 0644]
include/deal.II/lac/la_parallel_vector.h
include/deal.II/lac/la_parallel_vector.templates.h
include/deal.II/lac/petsc_vector.h
include/deal.II/lac/trilinos_vector.h
source/lac/petsc_parallel_vector.cc
source/lac/trilinos_vector.cc

diff --git a/doc/news/changes/minor/20221205Fehling b/doc/news/changes/minor/20221205Fehling
new file mode 100644 (file)
index 0000000..bd7eba9
--- /dev/null
@@ -0,0 +1,5 @@
+New: TrilinosWrappers::MPI::Vector and PETScWrappers::MPI::Vector now both have
+reinit functions that take a Utilities::MPI::Partitioner as an argument, so
+their interface is compatible to LinearAlgebra::distributed::Vector.
+<br>
+(Marc Fehling, 2022/12/05)
index 3ba62fd92788f2708befa3779d15805ff61bce43..31113568665d9c45ea3f36036300be59cef8e8e1 100644 (file)
@@ -405,6 +405,18 @@ namespace LinearAlgebra
         const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
         const MPI_Comm &comm_sm = MPI_COMM_SELF);
 
+      /**
+       * This function exists purely for reasons of compatibility with the
+       * PETScWrappers::MPI::Vector and TrilinosWrappers::MPI::Vector classes.
+       *
+       * It calls the function above, and ignores the parameter @p make_ghosted.
+       */
+      void
+      reinit(
+        const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
+        const bool                                                make_ghosted,
+        const MPI_Comm &comm_sm = MPI_COMM_SELF);
+
       /**
        * Initialize vector with @p local_size locally-owned and @p ghost_size
        * ghost degrees of freedoms.
index 596855e0720a26b0256cc7d6ce2717476f56f60e..ded3d505464fc0d517cf870501f09c07a10f30b9 100644 (file)
@@ -671,6 +671,18 @@ namespace LinearAlgebra
 
 
 
+    template <typename Number, typename MemorySpaceType>
+    void
+    Vector<Number, MemorySpaceType>::reinit(
+      const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner_in,
+      const bool /*make_ghosted*/,
+      const MPI_Comm &comm_sm)
+    {
+      this->reinit(partitioner_in, comm_sm);
+    }
+
+
+
     template <typename Number, typename MemorySpaceType>
     Vector<Number, MemorySpaceType>::Vector()
       : partitioner(std::make_shared<Utilities::MPI::Partitioner>())
index 842ec2dee4741d6861e44b6da5c0d658114ac324..0f654eea205ee05543cd3e2e0786ab0e4b81132a 100644 (file)
@@ -343,10 +343,14 @@ namespace PETScWrappers
       /**
        * Initialize the vector given to the parallel partitioning described in
        * @p partitioner.
+       *
+       * You can decide whether your vector will contain ghost elements with
+       * @p make_ghosted.
        */
       void
       reinit(
-        const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner);
+        const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
+        const bool make_ghosted = true);
 
       /**
        * Return a reference to the MPI communicator object in use with this
index fb0232102b44ec227dded147753484b544ffe5dc..63081cfe56f614ee5f9bdf5077c1eab49d8e7e28 100644 (file)
@@ -604,10 +604,17 @@ namespace TrilinosWrappers
       /**
        * Initialize the vector given to the parallel partitioning described in
        * @p partitioner using the function above.
+       *
+       * You can decide whether your vector will contain ghost elements with
+       * @p make_ghosted.
+       *
+       * The parameter @p vector_writable only has effect on ghosted vectors
+       * and is ignored for non-ghosted vectors.
        */
       void
       reinit(
         const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
+        const bool make_ghosted    = true,
         const bool vector_writable = false);
 
       /**
index 87242539d7cb2469b77fb28e5cc2cda851e0aaac..97ccf14e13e2f82529539a65fb630b89e878e648 100644 (file)
@@ -236,11 +236,24 @@ namespace PETScWrappers
 
     void
     Vector::reinit(
-      const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner)
+      const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
+      const bool                                                make_ghosted)
     {
-      this->reinit(partitioner->locally_owned_range(),
-                   partitioner->ghost_indices(),
-                   partitioner->get_mpi_communicator());
+      if (make_ghosted)
+        {
+          Assert(partitioner->ghost_indices_initialized(),
+                 ExcMessage("You asked to create a ghosted vector, but the "
+                            "partitioner does not provide ghost indices."));
+
+          this->reinit(partitioner->locally_owned_range(),
+                       partitioner->ghost_indices(),
+                       partitioner->get_mpi_communicator());
+        }
+      else
+        {
+          this->reinit(partitioner->locally_owned_range(),
+                       partitioner->get_mpi_communicator());
+        }
     }
 
 
index 58063a4a150db5708bb27289bc40e76fba30b6cb..8162488900812ecf225f40c3670c41f31a0cbb6d 100644 (file)
@@ -410,12 +410,25 @@ namespace TrilinosWrappers
     void
     Vector::reinit(
       const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner,
+      const bool                                                make_ghosted,
       const bool                                                vector_writable)
     {
-      this->reinit(partitioner->locally_owned_range(),
-                   partitioner->ghost_indices(),
-                   partitioner->get_mpi_communicator(),
-                   vector_writable);
+      if (make_ghosted)
+        {
+          Assert(partitioner->ghost_indices_initialized(),
+                 ExcMessage("You asked to create a ghosted vector, but the "
+                            "partitioner does not provide ghost indices."));
+
+          this->reinit(partitioner->locally_owned_range(),
+                       partitioner->ghost_indices(),
+                       partitioner->get_mpi_communicator(),
+                       vector_writable);
+        }
+      else
+        {
+          this->reinit(partitioner->locally_owned_range(),
+                       partitioner->get_mpi_communicator());
+        }
     }
 
 

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.