10#ifndef TPETRA_DETAILS_IDOT_HPP
11#define TPETRA_DETAILS_IDOT_HPP
30#include "Tpetra_MultiVector.hpp"
31#include "Tpetra_Vector.hpp"
32#include "Teuchos_CommHelpers.hpp"
33#include "KokkosBlas1_dot.hpp"
46 using DevView =
typename MV::dual_view_type::t_dev::const_type;
47 using HostView =
typename MV::dual_view_type::t_host::const_type;
49 template<
typename exec_space>
50 static DevView get(
const MV& x,
typename std::enable_if<std::is_same<exec_space, typename MV::execution_space>::value>::type* =
nullptr)
52 return x.getLocalViewDevice(Tpetra::Access::ReadOnly);
55 template<
typename exec_space>
56 static HostView get(
const MV& x,
typename std::enable_if<!std::is_same<exec_space, typename MV::execution_space>::value>::type* =
nullptr)
58 return x.getLocalViewHost(Tpetra::Access::ReadOnly);
64template<
class MV,
class ResultView,
bool runOnDevice>
69 using pair_type = Kokkos::pair<size_t, size_t>;
70 using exec_space =
typename std::conditional<runOnDevice, typename MV::execution_space, Kokkos::DefaultHostExecutionSpace>::type;
72 static_assert(Kokkos::SpaceAccessibility<exec_space, typename ResultView::memory_space>::accessible,
73 "idotLocal: Execution space must be able to access localResult");
76 Kokkos::View<typename ResultView::data_type, typename exec_space::memory_space, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
78 const size_t numRows =
X.getLocalLength ();
88 std::ostringstream
os;
89 os <<
"Tpetra::idot: X.getNumVectors() = " <<
X_numVecs
90 <<
" != Y.getNumVectors() = " <<
Y_numVecs
91 <<
", but neither is 1.";
92 throw std::invalid_argument (
os.str ());
134template<
typename MV,
typename ResultView>
137 using dot_type =
typename MV::dot_type;
140 template<
typename exec_space>
141 static std::shared_ptr< ::Tpetra::Details::CommRequest> run(
143 typename std::enable_if<Kokkos::SpaceAccessibility<exec_space, typename ResultView::memory_space>::accessible>::type* =
nullptr)
146 constexpr bool runOnDevice = std::is_same<exec_space, typename MV::execution_space>::value;
151 auto comm =
X.getMap()->getComm();
156 template<
typename exec_space>
157 static std::shared_ptr< ::Tpetra::Details::CommRequest> run(
158 const ResultView& globalResult,
const MV& X,
const MV& Y,
159 typename std::enable_if<!Kokkos::SpaceAccessibility<exec_space, typename ResultView::memory_space>::accessible>::type* =
nullptr)
161 constexpr bool runOnDevice = std::is_same<exec_space, typename MV::execution_space>::value;
162 Kokkos::View<dot_type*, typename exec_space::memory_space> localResult(Kokkos::ViewAllocateWithoutInitializing(
"idot:localResult"), X.getNumVectors());
163 idotLocal<MV, decltype(localResult), runOnDevice>(localResult, X, Y);
166 exec_space().fence();
167 auto comm = X.getMap()->getComm();
168 return iallreduce(localResult, globalResult, ::Teuchos::REDUCE_SUM, *comm);
176template<
class MV,
class ResultView>
177std::shared_ptr< ::Tpetra::Details::CommRequest>
182 static_assert(std::is_same<typename ResultView::non_const_value_type, typename MV::dot_type>::value,
183 "Tpetra::idot: result view's element type must match MV::dot_type");
186 if(
X.need_sync_device())
255template<
class SC,
class LO,
class GO,
class NT>
256std::shared_ptr< ::Tpetra::Details::CommRequest>
258 const ::Tpetra::MultiVector<SC, LO, GO, NT>&
X,
259 const ::Tpetra::MultiVector<SC, LO, GO, NT>&
Y)
261 using dot_type = typename ::Tpetra::Vector<SC, LO, GO, NT>::dot_type;
265 Kokkos::View<dot_type*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
332template<
class SC,
class LO,
class GO,
class NT>
333std::shared_ptr< ::Tpetra::Details::CommRequest>
334idot (
const Kokkos::View<typename ::Tpetra::MultiVector<SC, LO, GO, NT>::dot_type*,
335 typename ::Tpetra::MultiVector<SC, LO, GO, NT>::device_type>&
result,
336 const ::Tpetra::MultiVector<SC, LO, GO, NT>&
X,
337 const ::Tpetra::MultiVector<SC, LO, GO, NT>&
Y)
383template<
class SC,
class LO,
class GO,
class NT>
384std::shared_ptr< ::Tpetra::Details::CommRequest>
385idot (
const Kokkos::View<typename ::Tpetra::Vector<SC, LO, GO, NT>::dot_type,
386 typename ::Tpetra::Vector<SC, LO, GO, NT>::device_type>&
result,
387 const ::Tpetra::Vector<SC, LO, GO, NT>&
X,
388 const ::Tpetra::Vector<SC, LO, GO, NT>&
Y)
390 using dot_type = typename ::Tpetra::Vector<SC, LO, GO, NT>::dot_type;
391 using result_device_t = typename ::Tpetra::Vector<SC, LO, GO, NT>::device_type;
392 Kokkos::View<dot_type*, result_device_t, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
result1D(
result.data(), 1);
Declaration of Tpetra::iallreduce.
Struct that holds views of the contents of a CrsMatrix.
Implementation details of Tpetra.
std::shared_ptr< ::Tpetra::Details::CommRequest > idotImpl(const ResultView &globalResult, const MV &X, const MV &Y)
Internal (common) version of idot, a global dot product that uses a non-blocking MPI reduction.
void idotLocal(const ResultView &localResult, const MV &X, const MV &Y)
Compute dot product locally. Where the kernel runs controlled by runOnDevice.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
std::shared_ptr< ::Tpetra::Details::CommRequest > idot(typename ::Tpetra::MultiVector< SC, LO, GO, NT >::dot_type *resultRaw, const ::Tpetra::MultiVector< SC, LO, GO, NT > &X, const ::Tpetra::MultiVector< SC, LO, GO, NT > &Y)
Nonblocking dot product, with either Tpetra::MultiVector or Tpetra::Vector inputs,...