10 #ifndef TPETRA_KOKKOS_REFACTOR_DETAILS_MULTI_VECTOR_LOCAL_DEEP_COPY_HPP
11 #define TPETRA_KOKKOS_REFACTOR_DETAILS_MULTI_VECTOR_LOCAL_DEEP_COPY_HPP
13 #include "Kokkos_Core.hpp"
21 template <
class DstViewType,
class SrcViewType>
22 void copyConvertResolvingPossibleAliasing(
const DstViewType& dst,
23 const SrcViewType& src) {
29 const ptrdiff_t dst_beg =
reinterpret_cast<ptrdiff_t
>(dst.data());
30 const ptrdiff_t dst_end =
31 reinterpret_cast<ptrdiff_t
>(dst.data() + dst.span());
32 const ptrdiff_t src_beg =
reinterpret_cast<ptrdiff_t
>(src.data());
33 const ptrdiff_t src_end =
34 reinterpret_cast<ptrdiff_t
>(src.data() + src.span());
36 if (src_beg == dst_beg && src_end == dst_end) {
38 }
else if (dst_end <= src_beg || src_end <= dst_beg) {
48 auto src_copy = Kokkos::create_mirror(Kokkos::HostSpace(), src);
91 template <
class DstViewType,
93 class DstWhichVecsType,
94 class SrcWhichVecsType>
96 const SrcViewType& src,
97 const bool dstConstStride,
98 const bool srcConstStride,
99 const DstWhichVecsType& dstWhichVecs,
100 const SrcWhichVecsType& srcWhichVecs) {
102 using Kokkos::subview;
103 using size_type =
typename DstViewType::size_type;
105 if (dstConstStride && srcConstStride) {
106 copyConvertResolvingPossibleAliasing(dst, src);
108 const size_type numCols = dstConstStride ?
static_cast<size_type
>(srcWhichVecs.size()) : static_cast<size_type>(dstWhichVecs.size());
109 for (size_type j = 0; j < numCols; ++j) {
110 const size_type dst_col = dstConstStride ? j :
static_cast<size_type
>(dstWhichVecs[j]);
111 const auto dst_j = subview(dst, ALL(), dst_col);
112 const size_type src_col = srcConstStride ? j :
static_cast<size_type
>(srcWhichVecs[j]);
113 const auto src_j = subview(src, ALL(), src_col);
115 copyConvertResolvingPossibleAliasing(dst_j, src_j);
123 template <
class DstViewType,
126 const SrcViewType& src) {
127 return copyConvertResolvingPossibleAliasing(dst, src);
133 #endif // TPETRA_KOKKOS_REFACTOR_DETAILS_MULTI_VECTOR_LOCAL_DEEP_COPY_HPP
void localDeepCopyConstStride(const DstViewType &dst, const SrcViewType &src)
Implementation of Tpetra::MultiVector deep copy of local data, for when both the source and destinati...
Declare and define Tpetra::Details::copyConvert, an implementation detail of Tpetra (in particular...
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.
void copyConvert(const OutputViewType &dst, const InputViewType &src)
Copy values from the 1-D Kokkos::View src, to the 1-D Kokkos::View dst, of the same length...
void localDeepCopy(const DstViewType &dst, const SrcViewType &src, const bool dstConstStride, const bool srcConstStride, const DstWhichVecsType &dstWhichVecs, const SrcWhichVecsType &srcWhichVecs)
Implementation of Tpetra::MultiVector deep copy of local data.