]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement initialization
authorPeter Munch <peterrmuench@gmail.com>
Sat, 21 Mar 2020 18:32:27 +0000 (19:32 +0100)
committerPeter Munch <peterrmuench@gmail.com>
Sat, 21 Mar 2020 18:32:27 +0000 (19:32 +0100)
include/deal.II/lac/la_sm_partitioner.h
include/deal.II/lac/la_sm_vector.h
include/deal.II/lac/la_sm_vector.templates.h
include/deal.II/matrix_free/matrix_free.h
tests/sm/vector_sm_01.cc

index 02cc66481c8f7ee8921b3f271f2fbf305fdc00c5..aac7cc57e77ecf0009613cfffad35ea6b1fa7d43 100644 (file)
@@ -18,6 +18,7 @@
 
 
 #include <deal.II/base/config.h>
+
 #include <deal.II/base/mpi_compute_index_owner_internal.h>
 
 #include <deal.II/lac/communication_pattern_base.h>
@@ -33,7 +34,10 @@ namespace LinearAlgebra
     class Partitioner : public LinearAlgebra::CommunicationPatternBase
     {
     public:
-      Partitioner(const MPI_Comm &comm, const MPI_Comm &comm_sm, const IndexSet &is_locally_owned, const IndexSet &is_locally_ghost)
+      Partitioner(const MPI_Comm &comm,
+                  const MPI_Comm &comm_sm,
+                  const IndexSet &is_locally_owned,
+                  const IndexSet &is_locally_ghost)
         : comm(comm)
         , comm_sm(comm_sm)
       {
@@ -46,6 +50,12 @@ namespace LinearAlgebra
         return comm;
       }
 
+      const MPI_Comm &
+      get_sm_mpi_communicator() const
+      {
+        return comm_sm;
+      }
+
       void
       reinit(const IndexSet &is_locally_owned,
              const IndexSet &is_locally_ghost,
@@ -58,8 +68,7 @@ namespace LinearAlgebra
       }
 
       void
-      reinit(const IndexSet &is_locally_owned,
-             const IndexSet &is_locally_ghost)
+      reinit(const IndexSet &is_locally_owned, const IndexSet &is_locally_ghost)
       {
         this->n_local_elements = is_locally_owned.n_elements();
 
@@ -226,7 +235,7 @@ namespace LinearAlgebra
     private:
       const MPI_Comm &comm;
       const MPI_Comm &comm_sm;
-      
+
       unsigned int n_local_elements;
 
       AlignedVector<Number> buffer;
index 5a60b1dfab060950cc2ef64c98ca258fbeeb2dab..02c8508a2981f63b5f7cf0fd078521a095e71ea0 100644 (file)
@@ -494,7 +494,7 @@ namespace LinearAlgebra
       clear_mpi_requests();
 
       void
-      resize_val(const size_type new_allocated_size);
+      resize_val(const size_type new_allocated_size, const MPI_Comm &comm_sm);
 
       template <typename Number2, typename MemorySpace2>
       friend class Vector;
@@ -514,17 +514,15 @@ namespace LinearAlgebra
       struct Policy
       {
         static inline typename Vector<Number, MemorySpace>::iterator
-        begin(MemorySpaceData<Number> &)
+        begin(MemorySpaceData<Number> &data)
         {
-          Assert(false, ExcNotImplemented());
-          return nullptr;
+          return data.values.get();
         }
 
         static inline typename Vector<Number, MemorySpace>::const_iterator
-        begin(const MemorySpaceData<Number> &)
+        begin(const MemorySpaceData<Number> &data)
         {
-          Assert(false, ExcNotImplemented());
-          return nullptr;
+          return data.values.get();
         }
 
         static inline Number *
@@ -561,8 +559,7 @@ namespace LinearAlgebra
     inline typename Vector<Number, MemorySpace>::size_type
     Vector<Number, MemorySpace>::local_size() const
     {
-      Assert(false, ExcNotImplemented());
-      return 0;
+      return partitioner->local_size();
     }
 
 
@@ -638,7 +635,6 @@ namespace LinearAlgebra
     inline typename Vector<Number, MemorySpace>::iterator
     Vector<Number, MemorySpace>::begin()
     {
-      Assert(false, ExcNotImplemented());
       return internal::Policy<Number, MemorySpace>::begin(data);
     }
 
@@ -648,7 +644,6 @@ namespace LinearAlgebra
     inline typename Vector<Number, MemorySpace>::const_iterator
     Vector<Number, MemorySpace>::begin() const
     {
-      Assert(false, ExcNotImplemented());
       return internal::Policy<Number, MemorySpace>::begin(data);
     }
 
@@ -658,7 +653,6 @@ namespace LinearAlgebra
     inline typename Vector<Number, MemorySpace>::iterator
     Vector<Number, MemorySpace>::end()
     {
-      Assert(false, ExcNotImplemented());
       return internal::Policy<Number, MemorySpace>::begin(data) +
              partitioner->local_size();
     }
@@ -669,7 +663,6 @@ namespace LinearAlgebra
     inline typename Vector<Number, MemorySpace>::const_iterator
     Vector<Number, MemorySpace>::end() const
     {
-      Assert(false, ExcNotImplemented());
       return internal::Policy<Number, MemorySpace>::begin(data) +
              partitioner->local_size();
     }
index a55fd3d6afe53fde2939fa7c980841b9cf558a18..62826b57a523da1d144e873eaf566f72d2aab6ea 100644 (file)
@@ -48,7 +48,8 @@ namespace LinearAlgebra
         static void
         resize_val(const types::global_dof_index new_alloc_size,
                    types::global_dof_index &     allocated_size,
-                   MemorySpaceData<Number> &     data)
+                   MemorySpaceData<Number> &     data,
+                   const MPI_Comm &              comm_shared)
         {
           Assert(allocated_size == 0, ExcNotImplemented());
           Assert(data.values == nullptr, ExcNotImplemented());
@@ -57,7 +58,6 @@ namespace LinearAlgebra
 
           // TODO
           std::vector<Number *> data_others;
-          MPI_Comm              comm_shared;
 
           data.values_win   = new MPI_Win;
           Number *data_this = (Number *)malloc(0);
@@ -105,11 +105,15 @@ namespace LinearAlgebra
 
     template <typename Number, typename MemorySpaceType>
     void
-    Vector<Number, MemorySpaceType>::resize_val(const size_type new_alloc_size)
+    Vector<Number, MemorySpaceType>::resize_val(const size_type new_alloc_size,
+                                                const MPI_Comm &comm_sm)
     {
       internal::la_parallel_vector_templates_functions<
         Number,
-        MemorySpaceType>::resize_val(new_alloc_size, allocated_size, data);
+        MemorySpaceType>::resize_val(new_alloc_size,
+                                     allocated_size,
+                                     data,
+                                     comm_sm);
     }
 
 
@@ -181,7 +185,7 @@ namespace LinearAlgebra
       // set vector size and allocate memory
       const size_type new_allocated_size =
         this->partitioner->local_size() + this->partitioner->n_ghost_indices();
-      resize_val(new_allocated_size);
+      resize_val(new_allocated_size, partitioner_sm->get_sm_mpi_communicator());
 
       // initialize to zero
       this->operator=(Number());
@@ -274,7 +278,6 @@ namespace LinearAlgebra
     template <typename Number, typename MemorySpaceType>
     inline Vector<Number, MemorySpaceType>::~Vector()
     {
-      Assert(false, ExcNotImplemented());
       try
         {
           clear_mpi_requests();
@@ -363,7 +366,10 @@ namespace LinearAlgebra
     void
     Vector<Number, MemorySpaceType>::zero_out_ghosts() const
     {
-      Assert(false, ExcNotImplemented());
+      if (data.values != nullptr)
+        std::fill_n(data.values.get() + partitioner->local_size(),
+                    partitioner->n_ghost_indices(),
+                    Number());
     }
 
 
@@ -439,8 +445,12 @@ namespace LinearAlgebra
     Vector<Number, MemorySpaceType> &
     Vector<Number, MemorySpaceType>::operator=(const Number s)
     {
-      Assert(false, ExcNotImplemented());
-      (void)s;
+      const size_type this_size = local_size();
+      if (this_size > 0)
+        std::fill_n(data.values.get(), this_size, s);
+
+      if (s == Number())
+        zero_out_ghosts();
 
       return *this;
     }
index d8841bad932922e82647dee0491cd6a2faa68048..4f1f67e5d4354c9dbb3832e050429460e74910c5 100644 (file)
@@ -1482,7 +1482,7 @@ public:
   template <typename Number2>
   void
   initialize_dof_vector(LinearAlgebra::SharedMPI::Vector<Number2> &vec,
-                        const MPI_Comm &                            comm_sm,
+                        const MPI_Comm &                           comm_sm,
                         const unsigned int dof_handler_index = 0) const;
 
   /**
@@ -2231,17 +2231,20 @@ template <typename Number2>
 inline void
 MatrixFree<dim, Number, VectorizedArrayType>::initialize_dof_vector(
   LinearAlgebra::SharedMPI::Vector<Number2> &vec,
-  const MPI_Comm  &                           comm_sm,
+  const MPI_Comm &                           comm_sm,
   const unsigned int                         comp) const
 {
   AssertIndexRange(comp, n_components());
 
-  const auto & part = dof_info[comp].vector_partitioner;
-  
+  const auto &part = dof_info[comp].vector_partitioner;
+
   if (partitioner_sm[comp][comm_sm] == nullptr)
     partitioner_sm[comp][comm_sm] =
       std::make_shared<LinearAlgebra::SharedMPI::Partitioner<Number>>(
-        part->get_communicator(), comm_sm, part->locally_owned_range(), part->ghost_indices());
+        part->get_communicator(),
+        comm_sm,
+        part->locally_owned_range(),
+        part->ghost_indices());
 
   vec.reinit(part, partitioner_sm[comp][comm_sm]);
 }
index 1506d1064ca16a722011ca720dc1468b405eda1d..ec3622a90a474bd1e1013a545cd67441fb75b8d4 100644 (file)
@@ -61,9 +61,9 @@ test(const int n_refinements, const int degree, const int group_size)
   matrix_free.reinit(mapping, dof_handler, constraint, quad, additional_data);
 
   MPI_Comm comm = MPI_COMM_WORLD;
-  
+
   const unsigned int rank = Utilities::MPI::this_mpi_process(comm);
-  
+
   MPI_Comm comm_sm;
   MPI_Comm_split(comm, rank / group_size, rank, &comm_sm);
 

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.