44 #ifndef TPETRA_WITHLOCALACCESS_MULTIVECTOR_HPP
45 #define TPETRA_WITHLOCALACCESS_MULTIVECTOR_HPP
48 #include "Tpetra_MultiVector.hpp"
49 #include "Tpetra_Vector.hpp"
60 template<
class SC,
class LO,
class GO,
class NT,
88 static constexpr
bool is_host =
90 typename MemorySpace::execution_space::memory_space,
91 Kokkos::HostSpace>::value;
100 using master_local_view_type =
typename std::conditional<
102 typename dual_view_type::t_host,
103 typename dual_view_type::t_dev>::type;
106 (
static_cast<int> (master_local_view_type::Rank) == 2,
107 "Rank of master_local_view_type must be 2. "
108 "Please report this bug to the Tpetra developers.");
111 using master_local_object_type =
112 std::unique_ptr<master_local_view_type>;
115 static master_local_object_type
123 if (
static_cast<AccessMode> (am) == AccessMode::WriteOnly) {
124 LA.
G_.clear_sync_state ();
138 using space =
typename std::conditional<is_host,
139 typename dual_view_type::t_host::execution_space,
140 typename dual_view_type::t_dev::execution_space>::type;
142 if (LA.
G_.template need_sync<space> ()) {
143 LA.
G_.template sync<space> ();
149 if (
static_cast<AccessMode> (am) != AccessMode::ReadOnly) {
150 LA.
G_.template modify<space> ();
154 auto G_lcl_2d = LA.
G_.template getLocalView<space> ();
157 return std::unique_ptr<master_local_view_type>
158 (
new master_local_view_type (G_lcl_2d));
161 return std::unique_ptr<master_local_view_type>
162 (
new master_local_view_type ());
168 template<
class SC,
class LO,
class GO,
class NT,
182 using parent_master_local_view_type =
183 typename mv_gmlo::master_local_view_type;
184 using dual_view_type =
186 static constexpr
bool is_host = std::is_same<
187 typename MemorySpace::execution_space::memory_space,
188 Kokkos::HostSpace>::value;
198 using master_local_view_type = decltype (Kokkos::subview
199 (parent_master_local_view_type (), Kokkos::ALL (), 0));
202 (
static_cast<int> (master_local_view_type::Rank) == 1,
203 "Rank of master_local_view_type must be 1. "
204 "Please report this bug to the Tpetra developers.");
207 using master_local_object_type =
208 std::unique_ptr<master_local_view_type>;
211 static master_local_object_type
219 if (
static_cast<AccessMode> (am) == AccessMode::WriteOnly) {
220 LA.
G_.clear_sync_state ();
234 using space =
typename std::conditional<is_host,
235 typename dual_view_type::t_host::execution_space,
236 typename dual_view_type::t_dev::execution_space>::type;
238 if (LA.
G_.template need_sync<space> ()) {
239 LA.
G_.template sync<space> ();
245 if (
static_cast<AccessMode> (am) != AccessMode::ReadOnly) {
246 LA.
G_.template modify<space> ();
250 auto G_lcl_2d = LA.
G_.template getLocalView<space> ();
251 auto G_lcl_1d = Kokkos::subview (G_lcl_2d, Kokkos::ALL (), 0);
254 return std::unique_ptr<master_local_view_type>
255 (
new master_local_view_type (G_lcl_1d));
258 return std::unique_ptr<master_local_view_type>
259 (
new master_local_view_type ());
266 template<
class SC,
class LO,
class GO,
class NT,
278 using input_view_type =
288 using output_data_type =
typename std::conditional<
289 static_cast<AccessMode> (am) == AccessMode::ReadOnly,
290 typename input_view_type::const_data_type,
291 typename input_view_type::non_const_data_type>::type;
292 using output_view_type =
293 Kokkos::View<output_data_type,
294 typename input_view_type::array_layout,
295 typename input_view_type::device_type,
296 Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
298 using master_local_object_type =
300 using nonowning_local_object_type = output_view_type;
302 static nonowning_local_object_type
304 const master_local_object_type& M)
306 input_view_type* viewPtr = M.get ();
307 return viewPtr ==
nullptr ?
308 nonowning_local_object_type () :
309 nonowning_local_object_type (*viewPtr);
315 template<
class SC,
class LO,
class GO,
class NT,
327 using input_view_type =
336 using output_data_type =
typename std::conditional<
337 static_cast<AccessMode> (am) == AccessMode::ReadOnly,
338 typename input_view_type::const_data_type,
339 typename input_view_type::non_const_data_type>::type;
340 using output_view_type =
341 Kokkos::View<output_data_type,
342 typename input_view_type::array_layout,
343 typename input_view_type::device_type,
344 Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
346 using master_local_object_type =
348 using nonowning_local_object_type = output_view_type;
350 static nonowning_local_object_type
352 const master_local_object_type& M)
354 input_view_type* viewPtr = M.get ();
355 return viewPtr ==
nullptr ?
356 nonowning_local_object_type () :
357 nonowning_local_object_type (*viewPtr);
Declaration and definition of Tpetra::withLocalAccess; declaration of helper classes for users to spe...
Declaration of access intent for a global object.
global_object_type & G_
Reference to the global object whose data the user will access.
bool isValid() const
Is access supposed to be valid? (See valid() above.)
One or more distributed dense vectors.
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutLeft, execution_space > dual_view_type
Kokkos::DualView specialization used by this class.
A distributed dense vector.
Implementation details of Tpetra.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Mapping from LocalAccess to the "master" local object type.
Mapping from "master" local object type to the nonowning "local view" type that users see (as argumen...