From: Wolfgang Bangerth Date: Mon, 12 Feb 2024 20:26:14 +0000 (-0700) Subject: Rearrange code slightly. X-Git-Tag: relicensing~40^2~4 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c3f975fba617869038c66b8f888bc4306eb9abd;p=dealii.git Rearrange code slightly. --- diff --git a/include/deal.II/lac/trilinos_tpetra_vector.h b/include/deal.II/lac/trilinos_tpetra_vector.h index f84325aa87..640b33bdf1 100644 --- a/include/deal.II/lac/trilinos_tpetra_vector.h +++ b/include/deal.II/lac/trilinos_tpetra_vector.h @@ -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( - Tpetra::Access::ReadWrite); - auto vector_2d_nonlocal = + using ViewType2d = + decltype(vector->template getLocalView( + Tpetra::Access::ReadWrite)); + ViewType2d vector_2d_local = + vector->template getLocalView( + Tpetra::Access::ReadWrite); + ViewType2d vector_2d_nonlocal = nonlocal_vector->template getLocalView( Tpetra::Access::ReadWrite); # else vector->template sync(); - auto vector_2d_local = vector->template getLocalView(); - auto vector_2d_nonlocal = + + using ViewType2d = + decltype(vector->template getLocalView()); + ViewType2d vector_2d_local = + vector->template getLocalView(); + ViewType2d vector_2d_nonlocal = nonlocal_vector->template getLocalView(); # 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(); nonlocal_vector->template modify(); @@ -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::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::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::invalid(), - ExcAccessToNonLocalElement(row, - vector->getMap()->getLocalNumElements(), - vector->getMap()->getMinLocalIndex(), - vector->getMap()->getMaxLocalIndex())); + Assert(nonlocal_row != Teuchos::OrdinalTraits::invalid(), + ExcAccessToNonLocalElement( + row, + vector->getMap()->getLocalNumElements(), + vector->getMap()->getMinLocalIndex(), + vector->getMap()->getMaxLocalIndex())); # else - Assert( - local_row != Teuchos::OrdinalTraits::invalid(), - ExcAccessToNonLocalElement(row, - vector->getMap()->getNodeNumElements(), - vector->getMap()->getMinLocalIndex(), - vector->getMap()->getMaxLocalIndex())); + Assert(nonlocal_row != Teuchos::OrdinalTraits::invalid(), + ExcAccessToNonLocalElement( + row, + vector->getMap()->getNodeNumElements(), + vector->getMap()->getMinLocalIndex(), + vector->getMap()->getMaxLocalIndex())); # endif - if (local_row != Teuchos::OrdinalTraits::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; } }