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>();
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;
}
}