From 810153e5e5a9db6cf5785c2726aa151f3a1b25a3 Mon Sep 17 00:00:00 2001 From: Sebastian Kinnewig Date: Mon, 29 Jan 2024 21:12:33 +0100 Subject: [PATCH] just copy the content if the layout is the same --- .../lac/trilinos_tpetra_vector.templates.h | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) 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()) { -- 2.39.5