42 #ifndef TPETRA_DETAILS_ALLREDUCEVIEW_HPP
43 #define TPETRA_DETAILS_ALLREDUCEVIEW_HPP
47 #include "Kokkos_Core.hpp"
48 #include "Teuchos_CommHelpers.hpp"
49 #include "Tpetra_Details_temporaryViewUtils.hpp"
51 #include <type_traits>
59 template<
typename InputViewType,
typename OutputViewType>
61 allReduceRawContiguous (
const OutputViewType& output,
62 const InputViewType& input,
63 const Teuchos::Comm<int>& comm)
65 using Teuchos::outArg;
66 using Teuchos::REDUCE_SUM;
67 using Teuchos::reduceAll;
68 using ValueType =
typename InputViewType::non_const_value_type;
69 size_t count = input.span();
70 TEUCHOS_ASSERT( count <=
size_t (INT_MAX) );
71 if(
isInterComm(comm) && input.data() == output.data())
75 typename InputViewType::array_layout layout(input.extent(0), input.extent(1), input.extent(2), input.extent(3), input.extent(4), input.extent(5), input.extent(6), input.extent(7));
76 Kokkos::View<typename InputViewType::non_const_data_type, typename InputViewType::array_layout, typename InputViewType::device_type>
77 tempInput(Kokkos::ViewAllocateWithoutInitializing(
"tempInput"), layout);
81 reduceAll<int, ValueType> (comm, REDUCE_SUM,
static_cast<int> (count),
82 tempInput.data(), output.data());
85 reduceAll<int, ValueType> (comm, REDUCE_SUM,
static_cast<int> (count),
86 input.data(), output.data());
92 template<
class InputViewType,
class OutputViewType>
95 const InputViewType& input,
96 const Teuchos::Comm<int>& comm)
100 const bool viewsAlias = output.data () == input.data ();
101 if (comm.getSize () == 1) {
114 using Layout =
typename TempView::UnifiedContiguousLayout<InputViewType, OutputViewType>::type;
116 auto inputContig = TempView::toLayout<InputViewType, Layout>(input);
117 auto outputContig = TempView::toLayout<InputViewType, Layout>(output);
120 allReduceRawContiguous(outputContig, inputContig, comm);
125 auto inputMPI = TempView::toMPISafe<decltype(inputContig), false>(inputContig);
126 auto outputMPI = TempView::toMPISafe<decltype(outputContig), false>(outputContig);
127 allReduceRawContiguous(outputMPI, inputMPI, comm);
138 #endif // TPETRA_DETAILS_ALLREDUCEVIEW_HPP
static bool assumeMpiIsGPUAware()
Whether to assume that MPI is CUDA aware.
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.
static void allReduceView(const OutputViewType &output, const InputViewType &input, const Teuchos::Comm< int > &comm)
All-reduce from input Kokkos::View to output Kokkos::View.
bool isInterComm(const Teuchos::Comm< int > &)
Return true if and only if the input communicator wraps an MPI intercommunicator. ...
Declaration of Tpetra::Details::isInterComm.
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.