42#ifndef TPETRA_DETAILS_IDOT_HPP
43#define TPETRA_DETAILS_IDOT_HPP
62#include "Tpetra_MultiVector.hpp"
63#include "Tpetra_Vector.hpp"
64#include "Teuchos_CommHelpers.hpp"
65#include "KokkosBlas1_dot.hpp"
78 using DevView =
typename MV::dual_view_type::t_dev::const_type;
79 using HostView =
typename MV::dual_view_type::t_host::const_type;
81 template<
typename exec_space>
82 static DevView get(
const MV& x,
typename std::enable_if<std::is_same<exec_space, typename MV::execution_space>::value>::type* =
nullptr)
84 return x.getLocalViewDevice(Tpetra::Access::ReadOnly);
87 template<
typename exec_space>
88 static HostView get(
const MV& x,
typename std::enable_if<!std::is_same<exec_space, typename MV::execution_space>::value>::type* =
nullptr)
90 return x.getLocalViewHost(Tpetra::Access::ReadOnly);
96template<
class MV,
class ResultView,
bool runOnDevice>
101 using pair_type = Kokkos::pair<size_t, size_t>;
102 using exec_space =
typename std::conditional<runOnDevice, typename MV::execution_space, Kokkos::DefaultHostExecutionSpace>::type;
104 static_assert(Kokkos::SpaceAccessibility<exec_space, typename ResultView::memory_space>::accessible,
105 "idotLocal: Execution space must be able to access localResult");
108 Kokkos::View<typename ResultView::data_type, typename exec_space::memory_space, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
110 const size_t numRows =
X.getLocalLength ();
120 std::ostringstream
os;
121 os <<
"Tpetra::idot: X.getNumVectors() = " <<
X_numVecs
122 <<
" != Y.getNumVectors() = " <<
Y_numVecs
123 <<
", but neither is 1.";
124 throw std::invalid_argument (
os.str ());
166template<
typename MV,
typename ResultView>
169 using dot_type =
typename MV::dot_type;
172 template<
typename exec_space>
173 static std::shared_ptr< ::Tpetra::Details::CommRequest> run(
175 typename std::enable_if<Kokkos::SpaceAccessibility<exec_space, typename ResultView::memory_space>::accessible>::type* =
nullptr)
178 constexpr bool runOnDevice = std::is_same<exec_space, typename MV::execution_space>::value;
183 auto comm =
X.getMap()->getComm();
188 template<
typename exec_space>
189 static std::shared_ptr< ::Tpetra::Details::CommRequest> run(
190 const ResultView& globalResult,
const MV& X,
const MV& Y,
191 typename std::enable_if<!Kokkos::SpaceAccessibility<exec_space, typename ResultView::memory_space>::accessible>::type* =
nullptr)
193 constexpr bool runOnDevice = std::is_same<exec_space, typename MV::execution_space>::value;
194 Kokkos::View<dot_type*, typename exec_space::memory_space> localResult(Kokkos::ViewAllocateWithoutInitializing(
"idot:localResult"), X.getNumVectors());
195 idotLocal<MV, decltype(localResult), runOnDevice>(localResult, X, Y);
198 exec_space().fence();
199 auto comm = X.getMap()->getComm();
200 return iallreduce(localResult, globalResult, ::Teuchos::REDUCE_SUM, *comm);
208template<
class MV,
class ResultView>
209std::shared_ptr< ::Tpetra::Details::CommRequest>
214 static_assert(std::is_same<typename ResultView::non_const_value_type, typename MV::dot_type>::value,
215 "Tpetra::idot: result view's element type must match MV::dot_type");
218 if(
X.need_sync_device())
287template<
class SC,
class LO,
class GO,
class NT>
288std::shared_ptr< ::Tpetra::Details::CommRequest>
290 const ::Tpetra::MultiVector<SC, LO, GO, NT>&
X,
291 const ::Tpetra::MultiVector<SC, LO, GO, NT>&
Y)
293 using dot_type = typename ::Tpetra::Vector<SC, LO, GO, NT>::dot_type;
297 Kokkos::View<dot_type*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
364template<
class SC,
class LO,
class GO,
class NT>
365std::shared_ptr< ::Tpetra::Details::CommRequest>
366idot (
const Kokkos::View<typename ::Tpetra::MultiVector<SC, LO, GO, NT>::dot_type*,
367 typename ::Tpetra::MultiVector<SC, LO, GO, NT>::device_type>&
result,
368 const ::Tpetra::MultiVector<SC, LO, GO, NT>&
X,
369 const ::Tpetra::MultiVector<SC, LO, GO, NT>&
Y)
415template<
class SC,
class LO,
class GO,
class NT>
416std::shared_ptr< ::Tpetra::Details::CommRequest>
417idot (
const Kokkos::View<typename ::Tpetra::Vector<SC, LO, GO, NT>::dot_type,
418 typename ::Tpetra::Vector<SC, LO, GO, NT>::device_type>&
result,
419 const ::Tpetra::Vector<SC, LO, GO, NT>&
X,
420 const ::Tpetra::Vector<SC, LO, GO, NT>&
Y)
422 using dot_type = typename ::Tpetra::Vector<SC, LO, GO, NT>::dot_type;
423 using result_device_t = typename ::Tpetra::Vector<SC, LO, GO, NT>::device_type;
424 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,...