]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Rearrange code slightly.
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 12 Feb 2024 20:26:14 +0000 (13:26 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Mon, 12 Feb 2024 22:10:13 +0000 (15:10 -0700)
include/deal.II/lac/trilinos_tpetra_vector.h

index f84325aa870245c228aec2b991b4a776f23a19c0..640b33bdf14f7e3335a2bfb3762b8b3a5aa7a21f 100644 (file)
@@ -1003,22 +1003,40 @@ namespace LinearAlgebra
                                      const size_type *indices,
                                      const Number    *values)
     {
+      // First create an alias for the type of a view into our vectors.
+      // The actual type is declared through several re-directions in
+      // Tpetra, so instead of spelling it out, we get it via decltype:
 #  if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
-      auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>(
-        Tpetra::Access::ReadWrite);
-      auto vector_2d_nonlocal =
+      using ViewType2d =
+        decltype(vector->template getLocalView<Kokkos::HostSpace>(
+          Tpetra::Access::ReadWrite));
+      ViewType2d vector_2d_local =
+        vector->template getLocalView<Kokkos::HostSpace>(
+          Tpetra::Access::ReadWrite);
+      ViewType2d vector_2d_nonlocal =
         nonlocal_vector->template getLocalView<Kokkos::HostSpace>(
           Tpetra::Access::ReadWrite);
 #  else
       vector->template sync<Kokkos::HostSpace>();
-      auto vector_2d_local = vector->template getLocalView<Kokkos::HostSpace>();
-      auto vector_2d_nonlocal =
+
+      using ViewType2d =
+        decltype(vector->template getLocalView<Kokkos::HostSpace>());
+      ViewType2d vector_2d_local =
+        vector->template getLocalView<Kokkos::HostSpace>();
+      ViewType2d vector_2d_nonlocal =
         nonlocal_vector->template getLocalView<Kokkos::HostSpace>();
 #  endif
 
-      auto vector_1d_local = Kokkos::subview(vector_2d_local, Kokkos::ALL(), 0);
-      auto vector_1d_nonlocal =
+      // Having extracted a view into the multivectors above, now also
+      // extract a view into the one vector we actually store.
+      using ViewType1d =
+        decltype(Kokkos::subview(vector_2d_local, Kokkos::ALL(), 0));
+
+      ViewType1d vector_1d_local =
+        Kokkos::subview(vector_2d_local, Kokkos::ALL(), 0);
+      ViewType1d vector_1d_nonlocal =
         Kokkos::subview(vector_2d_nonlocal, Kokkos::ALL(), 0);
+
 #  if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
       vector->template modify<Kokkos::HostSpace>();
       nonlocal_vector->template modify<Kokkos::HostSpace>();
@@ -1026,42 +1044,45 @@ namespace LinearAlgebra
 
       for (size_type i = 0; i < n_elements; ++i)
         {
-          const size_type                   row = indices[i];
-          TrilinosWrappers::types::int_type local_row =
-            vector->getMap()->getLocalElement(row);
-
-          // check if the index is in the non local set
-          bool nonlocal = false;
-          if (local_row == Teuchos::OrdinalTraits<int>::invalid())
+          const size_type row = indices[i];
+
+          // Check if the index is in the locally owned index set.
+          // If so, we can write right into the locally owned
+          // part of the vector.
+          if (TrilinosWrappers::types::int_type local_row =
+                vector->getMap()->getLocalElement(row);
+              local_row != Teuchos::OrdinalTraits<int>::invalid())
             {
-              local_row  = nonlocal_vector->getMap()->getLocalElement(row);
-              nonlocal   = true;
-              compressed = false;
+              vector_1d_local(local_row) += values[i];
             }
+          else
+            {
+              // If the element was not in the locally owned part,
+              // we need to figure out whether it is in the nonlocal
+              // part. It better be:
+              TrilinosWrappers::types::int_type nonlocal_row =
+                nonlocal_vector->getMap()->getLocalElement(row);
 
 #  if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
-          Assert(
-            local_row != Teuchos::OrdinalTraits<int>::invalid(),
-            ExcAccessToNonLocalElement(row,
-                                       vector->getMap()->getLocalNumElements(),
-                                       vector->getMap()->getMinLocalIndex(),
-                                       vector->getMap()->getMaxLocalIndex()));
+              Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
+                     ExcAccessToNonLocalElement(
+                       row,
+                       vector->getMap()->getLocalNumElements(),
+                       vector->getMap()->getMinLocalIndex(),
+                       vector->getMap()->getMaxLocalIndex()));
 #  else
-          Assert(
-            local_row != Teuchos::OrdinalTraits<int>::invalid(),
-            ExcAccessToNonLocalElement(row,
-                                       vector->getMap()->getNodeNumElements(),
-                                       vector->getMap()->getMinLocalIndex(),
-                                       vector->getMap()->getMaxLocalIndex()));
+              Assert(nonlocal_row != Teuchos::OrdinalTraits<int>::invalid(),
+                     ExcAccessToNonLocalElement(
+                       row,
+                       vector->getMap()->getNodeNumElements(),
+                       vector->getMap()->getMinLocalIndex(),
+                       vector->getMap()->getMaxLocalIndex()));
 
 #  endif
 
-          if (local_row != Teuchos::OrdinalTraits<int>::invalid())
-            {
-              if (nonlocal)
-                vector_1d_nonlocal(local_row) += values[i];
-              else
-                vector_1d_local(local_row) += values[i];
+              // Having asserted that it is, write into the nonlocal part.
+              vector_1d_nonlocal(nonlocal_row) += values[i];
+              compressed = false;
             }
         }
 

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.