42 #ifndef TPETRA_WITHLOCALACCESS_MULTIVECTOR_HPP
43 #define TPETRA_WITHLOCALACCESS_MULTIVECTOR_HPP
46 #include "Tpetra_MultiVector.hpp"
47 #include "Tpetra_Vector.hpp"
61 template<
class SC,
class LO,
class GO,
class NT,
class ... Args>
62 struct GetMasterLocalObject<
63 LocalAccess<Tpetra::MultiVector<SC, LO, GO, NT>, Args...>
65 template<class SC, class LO, class GO, class NT, class ... Args>
66 struct GetMasterLocalObject<
67 LocalAccess<Tpetra::Vector<SC, LO, GO, NT>, Args...>
70 template<class SC, class LO, class GO, class NT, class ... Args>
71 struct GetNonowningLocalObject<
72 LocalAccess<Tpetra::MultiVector<SC, LO, GO, NT>, Args...>
74 template<class SC, class LO, class GO, class NT, class ... Args>
75 struct GetNonowningLocalObject<
76 LocalAccess<Tpetra::Vector<SC, LO, GO, NT>, Args...>
82 struct is_host_space {
92 static constexpr
bool value =
93 std::is_same<
typename Space::execution_space::memory_space,
94 Kokkos::HostSpace>::value;
100 template<
class SC,
class LO,
class GO,
class NT,
class ... Args>
113 using execution_space =
114 typename local_access_type::execution_space;
116 Kokkos::Impl::is_execution_space<execution_space>::value,
117 "LocalAccess<Args...>::execution_space is not a valid "
118 "Kokkos execution space.");
120 using memory_space =
typename local_access_type::memory_space;
122 Kokkos::Impl::is_memory_space<memory_space>::value,
123 "LocalAccess<Args...>::memory_space is not a valid "
124 "Kokkos memory space.");
126 using access_mode =
typename local_access_type::access_mode;
128 is_access_mode<access_mode>::value,
129 "LocalAccess<Args...>::access_mode is not an Access "
142 using dual_view_type =
152 using master_local_view_type =
typename std::conditional<
153 is_host_space<execution_space>::value,
154 typename dual_view_type::t_host,
155 typename dual_view_type::t_dev>::type;
158 static_cast<int>(master_local_view_type::Rank) == 2,
159 "Rank of master_local_view_type must be 2. "
160 "Please report this bug to the Tpetra developers.");
163 static master_local_view_type
167 return master_local_view_type();
170 using access_mode =
typename local_access_type::access_mode;
171 constexpr
bool is_write_only =
172 std::is_same<access_mode, Access::WriteOnly>::value;
174 LA.
G_.clear_sync_state();
206 if (LA.
G_.template need_sync<execution_space>()) {
207 LA.
G_.template sync<execution_space>();
210 constexpr
bool is_read_only =
211 std::is_same<access_mode, Access::ReadOnly>::value;
212 if (! is_read_only) {
213 LA.
G_.template modify<execution_space>();
218 LA.
G_.template getLocalView<execution_space>();
220 return master_local_view_type(G_lcl_2d);
229 using master_local_object_type = std::unique_ptr<
230 master_local_view_type>;
233 static master_local_object_type
236 auto G_lcl_2d = getOwningPreActions(LA);
241 return master_local_object_type(
242 new master_local_view_type(G_lcl_2d));
250 >::master_local_view_type
251 >::value,
"Missing GetMasterLocalObject specialization");
257 >::master_local_view_type
258 >::value,
"Missing GetMasterLocalObject specialization");
263 template<
class SC,
class LO,
class GO,
class NT,
class ... Args>
276 using execution_space =
277 typename local_access_type::execution_space;
279 Kokkos::Impl::is_execution_space<execution_space>::value,
280 "LocalAccess<Args...>::execution_space is not a valid "
281 "Kokkos execution space.");
283 using memory_space =
typename local_access_type::memory_space;
285 Kokkos::Impl::is_memory_space<memory_space>::value,
286 "LocalAccess<Args...>::memory_space is not a valid "
287 "Kokkos memory space.");
289 using access_mode =
typename local_access_type::access_mode;
291 is_access_mode<access_mode>::value,
292 "LocalAccess<Args...>::access_mode is not an Access "
305 using dual_view_type =
310 using master_local_view_2d_type =
typename std::conditional<
311 is_host_space<execution_space>::value,
312 typename dual_view_type::t_host,
313 typename dual_view_type::t_dev>::type;
319 using master_local_view_type = decltype(
320 Kokkos::subview(master_local_view_2d_type(),
324 static_cast<int>(master_local_view_type::Rank) == 1,
325 "Rank of master_local_view_type must be 1. "
326 "Please report this bug to the Tpetra developers.");
329 static master_local_view_2d_type
333 return master_local_view_2d_type();
336 using access_mode =
typename local_access_type::access_mode;
337 constexpr
bool is_write_only =
338 std::is_same<access_mode, Access::WriteOnly>::value;
340 LA.
G_.clear_sync_state();
343 if (LA.
G_.template need_sync<execution_space>()) {
344 LA.
G_.template sync<execution_space>();
347 constexpr
bool is_read_only =
348 std::is_same<access_mode, Access::ReadOnly>::value;
349 if (! is_read_only) {
350 LA.
G_.template modify<execution_space>();
355 LA.
G_.template getLocalView<execution_space>();
357 return master_local_view_2d_type(G_lcl_2d);
366 using master_local_object_type = std::unique_ptr<
367 master_local_view_type>;
370 static master_local_object_type
373 master_local_view_2d_type G_lcl_2d = getOwningPreActions(LA);
374 master_local_view_type G_lcl_1d =
375 Kokkos::subview(G_lcl_2d, Kokkos::ALL(), 0);
381 return master_local_object_type(
382 new master_local_view_type(G_lcl_1d));
390 >::master_local_view_type
391 >::value,
"Missing GetMasterLocalObject specialization");
397 >::master_local_view_type
398 >::value,
"Missing GetMasterLocalObject specialization");
405 template<
class SC,
class LO,
class GO,
class NT,
class ... Args>
417 using access_mode =
typename local_access_type::access_mode;
418 static_assert(is_access_mode<access_mode>::value,
419 "Please report this bug to the Tpetra developers.");
421 using master_local_view_type =
423 master_local_view_type;
425 static_cast<int>(master_local_view_type::Rank) == 2,
426 "Rank of master_local_view_type must be 2.");
431 using output_data_type =
typename std::conditional<
432 std::is_same<access_mode, Access::ReadOnly>::value,
433 typename master_local_view_type::const_data_type,
434 typename master_local_view_type::non_const_data_type>::type;
437 using master_local_object_type =
439 master_local_object_type;
440 using nonowning_local_object_type =
441 Kokkos::View<output_data_type,
442 typename master_local_view_type::array_layout,
443 typename master_local_view_type::device_type,
444 Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
446 static nonowning_local_object_type
448 const master_local_object_type& M)
450 master_local_view_type* viewPtr = M.get();
451 return viewPtr ==
nullptr ?
452 nonowning_local_object_type() :
453 nonowning_local_object_type(*viewPtr);
461 template<
class SC,
class LO,
class GO,
class NT,
class ... Args>
473 using access_mode =
typename local_access_type::access_mode;
474 static_assert(is_access_mode<access_mode>::value,
475 "Please report this bug to the Tpetra developers.");
477 using master_local_view_type =
479 master_local_view_type;
481 static_cast<int>(master_local_view_type::Rank) == 1,
482 "Rank of master_local_view_type must be 1.");
486 using output_data_type =
typename std::conditional<
487 std::is_same<access_mode, Access::ReadOnly>::value,
488 typename master_local_view_type::const_data_type,
489 typename master_local_view_type::non_const_data_type>::type;
492 using master_local_object_type =
494 master_local_object_type;
495 using nonowning_local_object_type =
496 Kokkos::View<output_data_type,
497 typename master_local_view_type::array_layout,
498 typename master_local_view_type::device_type,
499 Kokkos::MemoryTraits<Kokkos::Unmanaged> >;
501 static nonowning_local_object_type
503 const master_local_object_type& M)
505 master_local_view_type* viewPtr = M.get();
506 return viewPtr ==
nullptr ?
507 nonowning_local_object_type() :
508 nonowning_local_object_type(*viewPtr);
515 #endif // TPETRA_WITHLOCALACCESS_MULTIVECTOR_HPP
Mapping from "master" local object type to the nonowning "local view" type that users see (as argumen...
Declaration of access intent for a global object.
Kokkos::DualView< impl_scalar_type **, Kokkos::LayoutLeft, device_type > dual_view_type
Kokkos::DualView specialization used by this class.
global_object_type & G_
Reference to the global object whose data the user will access.
One or more distributed dense vectors.
Declaration and definition of Tpetra::withLocalAccess; declaration of helper classes for users to spe...
A distributed dense vector.
bool isValid() const
Is access supposed to be valid?
base_type::dual_view_type dual_view_type
Kokkos::DualView specialization used by this class.
Mapping from LocalAccess to the "master" local object type.