From: Sebastian Kinnewig Date: Mon, 29 Jan 2024 20:12:33 +0000 (+0100) Subject: just copy the content if the layout is the same X-Git-Tag: relicensing~99^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16558%2Fhead;p=dealii.git just copy the content if the layout is the same --- diff --git a/include/deal.II/lac/trilinos_tpetra_vector.templates.h b/include/deal.II/lac/trilinos_tpetra_vector.templates.h index d9d9519cb2..f1c5a0cc69 100644 --- a/include/deal.II/lac/trilinos_tpetra_vector.templates.h +++ b/include/deal.II/lac/trilinos_tpetra_vector.templates.h @@ -289,7 +289,43 @@ namespace LinearAlgebra // - Third case: the vectors have different size. if (vector->getMap()->isSameAs(*V.vector->getMap())) { - *vector = Tpetra::createCopy(*V.vector); + // Create a read-only Kokkos view from the source vector +# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0) + auto source_vector_2d = + V.vector->template getLocalView( + Tpetra::Access::ReadOnly); +# else + auto source_vector_2d = + V.vector->template getLocalView(); +# endif + auto source_vector_1d = + Kokkos::subview(source_vector_2d, Kokkos::ALL(), 0); + + // Create a read/write Kokkos view from the target vector +# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0) + auto target_vector_2d = + vector->template getLocalView( + Tpetra::Access::ReadWrite); +# else + vector->template sync(); + auto target_vector_2d = + vector->template getLocalView(); +# endif + auto target_vector_1d = + Kokkos::subview(target_vector_2d, Kokkos::ALL(), 0); +# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0) + vector->template modify(); +# endif + + // Copy the data + Kokkos::deep_copy(target_vector_1d, source_vector_1d); + +# if !DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0) + vector->template sync::device_type::memory_space>(); +# endif } else if (size() == V.size()) {