Skip to content

Commit

Permalink
Merge pull request #16558 from kinnewig/copy-assignment
Browse files Browse the repository at this point in the history
Make a deep-copy of the Tpetra::Vector in the assignment operator.
  • Loading branch information
bangerth committed Jan 30, 2024
2 parents 62c6cce + 810153e commit d68d8b4
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions include/deal.II/lac/trilinos_tpetra_vector.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,43 @@ namespace LinearAlgebra
// - Third case: the vectors have different size.
if (vector->getMap()->isSameAs(*V.vector->getMap()))
{
*vector = *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<Kokkos::HostSpace>(
Tpetra::Access::ReadOnly);
# else
auto source_vector_2d =
V.vector->template getLocalView<Kokkos::HostSpace>();
# 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<Kokkos::HostSpace>(
Tpetra::Access::ReadWrite);
# else
vector->template sync<Kokkos::HostSpace>();
auto target_vector_2d =
vector->template getLocalView<Kokkos::HostSpace>();
# 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<Kokkos::HostSpace>();
# 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<typename Tpetra::Vector<
Number,
int,
types::signed_global_dof_index>::device_type::memory_space>();
# endif
}
else if (size() == V.size())
{
Expand Down Expand Up @@ -314,9 +350,9 @@ namespace LinearAlgebra
else
{
vector.reset();
vector = Utilities::Trilinos::internal::make_rcp<VectorType>(
V.vector->getMap());
Tpetra::deep_copy(*vector, *V.vector);
vector =
Utilities::Trilinos::internal::make_rcp<VectorType>(*V.vector,
Teuchos::Copy);

compressed = V.compressed;
has_ghost = V.has_ghost;
Expand Down

0 comments on commit d68d8b4

Please sign in to comment.