Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Details_getEntryOnHost.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TPETRA_DETAILS_GETENTRYONHOST_HPP
11 #define TPETRA_DETAILS_GETENTRYONHOST_HPP
12 
18 
19 #include "TpetraCore_config.h"
20 #include "Kokkos_Core.hpp"
21 
22 namespace Tpetra {
23 namespace Details {
24 
25 template <class ViewType,
26  class IndexType>
27 typename ViewType::non_const_value_type
28 getEntryOnHost(const ViewType& x,
29  const IndexType ind) {
30  using execution_space = typename ViewType::execution_space;
31  static_assert(ViewType::rank == 1, "x must be a rank-1 Kokkos::View.");
32  // Get a 0-D subview of the entry of the array, and copy to host scalar.
33  typename ViewType::non_const_value_type val;
34  // DEEP_COPY REVIEW - DEVICE-TO-VALUE
35  Kokkos::deep_copy(execution_space(), val, Kokkos::subview(x, ind));
36  return val;
37 }
38 
39 template <class ViewType,
40  class IndexType>
41 typename ViewType::host_mirror_type::const_type
42 getEntriesOnHost(const ViewType& x,
43  const IndexType ind,
44  const int count) {
45  static_assert(ViewType::rank == 1, "x must be a rank-1 Kokkos::View.");
46  // Get a 1-D subview of the entry of the array, and copy to host.
47  auto subview = Kokkos::subview(x, Kokkos::make_pair(ind, ind + count));
48  return Kokkos::create_mirror_view_and_copy(typename ViewType::host_mirror_type::memory_space(), subview);
49 }
50 
51 } // namespace Details
52 } // namespace Tpetra
53 
54 #endif // TPETRA_DETAILS_GETENTRYONHOST_HPP
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.