]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid the use of one variable.
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 29 Jul 2021 23:57:00 +0000 (17:57 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 4 Aug 2021 15:21:50 +0000 (09:21 -0600)
This shrinks the object that contains this variable as a member, but also
avoids a warning about an unused variable in one place. Finally, change the
order of destruction from end to beginning.

include/deal.II/base/aligned_vector.h

index 0924e470935b6e3fee354927897ceaafbe297bb9..e6ed66e0106badea65f04dab42825082a451e6d6 100644 (file)
@@ -575,7 +575,6 @@ private:
      */
     Deleter(AlignedVector<T> *owning_object,
             const bool        is_shmem_root,
-            const size_type   array_size,
             T *               aligned_shmem_pointer,
             MPI_Comm          shmem_group_communicator,
             MPI_Win           shmem_window);
@@ -633,11 +632,10 @@ private:
        * Constructor. Store the various pieces of information necessary to
        * identify the MPI window in which the data resides.
        */
-      MPISharedMemDeleterAction(const bool      is_shmem_root,
-                                const size_type array_size,
-                                T *             aligned_shmem_pointer,
-                                MPI_Comm        shmem_group_communicator,
-                                MPI_Win         shmem_window);
+      MPISharedMemDeleterAction(const bool is_shmem_root,
+                                T *        aligned_shmem_pointer,
+                                MPI_Comm   shmem_group_communicator,
+                                MPI_Win    shmem_window);
 
       /**
        * The function that implements the action of de-allocating memory.
@@ -652,11 +650,10 @@ private:
        * Variables necessary to identify the MPI shared-memory window plus
        * all ancillary information to destroy this window.
        */
-      const bool      is_shmem_root;
-      const size_type array_size;
-      T *             aligned_shmem_pointer;
-      MPI_Comm        shmem_group_communicator;
-      MPI_Win         shmem_window;
+      const bool is_shmem_root;
+      T *        aligned_shmem_pointer;
+      MPI_Comm   shmem_group_communicator;
+      MPI_Win    shmem_window;
     };
 #endif
 
@@ -1058,13 +1055,11 @@ inline AlignedVector<T>::Deleter::Deleter(AlignedVector<T> *owning_object)
 template <typename T>
 inline AlignedVector<T>::Deleter::Deleter(AlignedVector<T> *owning_object,
                                           const bool        is_shmem_root,
-                                          const size_type   array_size,
                                           T *      aligned_shmem_pointer,
                                           MPI_Comm shmem_group_communicator,
                                           MPI_Win  shmem_window)
   : deleter_action_object(
       std::make_unique<MPISharedMemDeleterAction>(is_shmem_root,
-                                                  array_size,
                                                   aligned_shmem_pointer,
                                                   shmem_group_communicator,
                                                   shmem_window))
@@ -1114,13 +1109,11 @@ AlignedVector<T>::Deleter::reset_owning_object(
 
 template <typename T>
 inline AlignedVector<T>::Deleter::MPISharedMemDeleterAction::
-  MPISharedMemDeleterAction(const bool      is_shmem_root,
-                            const size_type array_size,
-                            T *             aligned_shmem_pointer,
-                            MPI_Comm        shmem_group_communicator,
-                            MPI_Win         shmem_window)
+  MPISharedMemDeleterAction(const bool is_shmem_root,
+                            T *        aligned_shmem_pointer,
+                            MPI_Comm   shmem_group_communicator,
+                            MPI_Win    shmem_window)
   : is_shmem_root(is_shmem_root)
-  , array_size(array_size)
   , aligned_shmem_pointer(aligned_shmem_pointer)
   , shmem_group_communicator(shmem_group_communicator)
   , shmem_window(shmem_window)
@@ -1134,9 +1127,15 @@ AlignedVector<T>::Deleter::MPISharedMemDeleterAction::delete_array(
   const AlignedVector<T> *aligned_vector,
   T *                     ptr)
 {
+  (void)ptr;
+  Assert(aligned_vector->elements.get() == ptr, ExcInternalError());
+
   if (is_shmem_root)
-    for (unsigned int i = 0; i < array_size; ++i)
-      aligned_shmem_pointer[i].~T();
+    if (std::is_trivial<T>::value == false)
+      for (T *p = aligned_vector->used_elements_end - 1;
+           p >= aligned_vector->elements.get();
+           --p)
+        p->~T();
 
   int ierr;
   ierr = MPI_Win_free(&shmem_window);
@@ -1854,7 +1853,6 @@ AlignedVector<T>::replicate_across_communicator(const MPI_Comm &   communicator,
   elements = decltype(elements)(aligned_shmem_pointer,
                                 Deleter(this,
                                         is_shmem_root,
-                                        array_size,
                                         aligned_shmem_pointer,
                                         shmem_group_communicator,
                                         shmem_window));

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.