42 #ifndef TPETRA_DETAILS_IALLREDUCE_HPP 43 #define TPETRA_DETAILS_IALLREDUCE_HPP 61 #include "TpetraCore_config.h" 62 #include "Teuchos_EReductionType.hpp" 63 #ifdef HAVE_TPETRACORE_MPI 66 #endif // HAVE_TPETRACORE_MPI 67 #include "Kokkos_Core.hpp" 70 #include <type_traits> 73 #ifndef DOXYGEN_SHOULD_SKIP_THIS 76 template<
class OrdinalType>
class Comm;
78 #endif // NOT DOXYGEN_SHOULD_SKIP_THIS 94 virtual void wait () = 0;
99 virtual void cancel () = 0;
109 std::shared_ptr<CommRequest>
112 #ifdef HAVE_TPETRACORE_MPI 133 MpiCommRequest (
const MPI_Request req);
136 virtual ~MpiCommRequest ();
143 virtual void wait ();
151 virtual void waitWithStatus (MPI_Status& status);
154 virtual void cancel ();
159 #endif // HAVE_TPETRACORE_MPI 189 std::function<void(void) > action_;
220 template<
class PacketType,
221 class SendLayoutType,
222 class SendDeviceType,
223 class RecvLayoutType,
224 class RecvDeviceType,
229 template<
class PacketType,
230 class SendLayoutType,
231 class SendDeviceType,
232 class RecvLayoutType,
233 class RecvDeviceType>
247 typedef ::Kokkos::View<
const PacketType*, SendLayoutType,
250 typedef ::Kokkos::View<PacketType*, RecvLayoutType,
257 const send_buffer_type& sendbuf,
258 const recv_buffer_type& recvbuf) :
263 static_assert (std::is_same<SendLayoutType, ::Kokkos::LayoutLeft>::value ||
264 std::is_same<SendLayoutType, ::Kokkos::LayoutRight>::value,
265 "SendLayoutType must be either Kokkos::LayoutLeft or " 266 "Kokkos::LayoutRight.");
267 static_assert (std::is_same<RecvLayoutType, ::Kokkos::LayoutLeft>::value ||
268 std::is_same<RecvLayoutType, ::Kokkos::LayoutRight>::value,
269 "RecvLayoutType must be either Kokkos::LayoutLeft or " 270 "Kokkos::LayoutRight.");
275 if (req_.get () != NULL) {
284 req_ = std::shared_ptr<CommRequest> ();
297 if (req_.get () != NULL) {
300 req_ = std::shared_ptr<CommRequest> ();
304 sendbuf_ = send_buffer_type ();
305 recvbuf_ = recv_buffer_type ();
314 if (req_.get () != NULL) {
317 req_ = std::shared_ptr<CommRequest> ();
321 sendbuf_ = send_buffer_type ();
322 recvbuf_ = recv_buffer_type ();
327 std::shared_ptr<CommRequest> req_;
330 send_buffer_type sendbuf_;
333 recv_buffer_type recvbuf_;
337 template<
class PacketType,
338 class SendLayoutType,
339 class SendDeviceType,
340 class RecvLayoutType,
341 class RecvDeviceType>
355 typedef ::Kokkos::View<
const PacketType, SendLayoutType,
358 typedef ::Kokkos::View<PacketType, RecvLayoutType,
365 const send_buffer_type& sendbuf,
366 const recv_buffer_type& recvbuf) :
371 static_assert (std::is_same<SendLayoutType, ::Kokkos::LayoutLeft>::value ||
372 std::is_same<SendLayoutType, ::Kokkos::LayoutRight>::value,
373 "SendLayoutType must be either Kokkos::LayoutLeft or " 374 "Kokkos::LayoutRight.");
375 static_assert (std::is_same<RecvLayoutType, ::Kokkos::LayoutLeft>::value ||
376 std::is_same<RecvLayoutType, ::Kokkos::LayoutRight>::value,
377 "RecvLayoutType must be either Kokkos::LayoutLeft or " 378 "Kokkos::LayoutRight.");
383 if (req_.get () != NULL) {
392 req_ = std::shared_ptr<CommRequest> ();
405 if (req_.get () != NULL) {
408 req_ = std::shared_ptr<CommRequest> ();
412 sendbuf_ = send_buffer_type ();
413 recvbuf_ = recv_buffer_type ();
422 if (req_.get () != NULL) {
425 req_ = std::shared_ptr<CommRequest> ();
429 sendbuf_ = send_buffer_type ();
430 recvbuf_ = recv_buffer_type ();
435 std::shared_ptr<CommRequest> req_;
438 send_buffer_type sendbuf_;
441 recv_buffer_type recvbuf_;
476 template<
class PacketType,
477 class SendLayoutType,
478 class SendDeviceType,
479 class RecvLayoutType,
480 class RecvDeviceType>
481 std::shared_ptr<CommRequest>
483 const ::Kokkos::View<
const PacketType*,
485 SendDeviceType>& sendbuf,
486 const ::Kokkos::View<PacketType*,
488 RecvDeviceType>& recvbuf)
490 static_assert (std::is_same<SendLayoutType, ::Kokkos::LayoutLeft>::value ||
491 std::is_same<SendLayoutType, ::Kokkos::LayoutRight>::value,
492 "SendLayoutType must be either Kokkos::LayoutLeft or " 493 "Kokkos::LayoutRight.");
494 static_assert (std::is_same<RecvLayoutType, ::Kokkos::LayoutLeft>::value ||
495 std::is_same<RecvLayoutType, ::Kokkos::LayoutRight>::value,
496 "RecvLayoutType must be either Kokkos::LayoutLeft or " 497 "Kokkos::LayoutRight.");
499 RecvLayoutType, RecvDeviceType, 1> req_type;
500 return std::shared_ptr<CommRequest> (
new req_type (req, sendbuf, recvbuf));
535 template<
class PacketType,
536 class SendLayoutType,
537 class SendDeviceType,
538 class RecvLayoutType,
539 class RecvDeviceType>
540 std::shared_ptr<CommRequest>
542 const ::Kokkos::View<
const PacketType,
544 SendDeviceType>& sendbuf,
545 const ::Kokkos::View<PacketType,
547 RecvDeviceType>& recvbuf)
549 static_assert (std::is_same<SendLayoutType, ::Kokkos::LayoutLeft>::value ||
550 std::is_same<SendLayoutType, ::Kokkos::LayoutRight>::value,
551 "SendLayoutType must be either Kokkos::LayoutLeft or " 552 "Kokkos::LayoutRight.");
553 static_assert (std::is_same<RecvLayoutType, ::Kokkos::LayoutLeft>::value ||
554 std::is_same<RecvLayoutType, ::Kokkos::LayoutRight>::value,
555 "RecvLayoutType must be either Kokkos::LayoutLeft or " 556 "Kokkos::LayoutRight.");
558 RecvLayoutType, RecvDeviceType, 0> req_type;
559 return std::shared_ptr<CommRequest> (
new req_type (req, sendbuf, recvbuf));
562 #ifdef HAVE_TPETRACORE_MPI 574 std::shared_ptr<CommRequest>
575 iallreduceRawVoid (
const void* sendbuf,
578 MPI_Datatype mpiDatatype,
579 const bool mpiDatatypeNeedsFree,
580 const Teuchos::EReductionType op,
583 #endif // HAVE_TPETRACORE_MPI 593 template<
class Packet>
594 std::shared_ptr<CommRequest>
598 const ::Teuchos::EReductionType op,
599 const ::Teuchos::Comm<int>& comm)
601 #ifdef HAVE_TPETRACORE_MPI 602 using ::Tpetra::Details::MpiTypeTraits;
617 MPI_Datatype mpiDatatype = (count > 0) ?
618 MpiTypeTraits<Packet>::getType (sendbuf[0]) :
620 MPI_Comm rawComm = ::Tpetra::Details::extractMpiCommFromTeuchos (comm);
621 return iallreduceRawVoid (sendbuf, recvbuf, count, mpiDatatype,
622 MpiTypeTraits<Packet>::needsFree, op, rawComm);
623 #else // NOT HAVE_TPETRACORE_MPI 624 throw std::logic_error (
"Tpetra::Details::Impl::iallreduceRaw: This function " 625 "should never be called if MPI is not enabled. " 626 "Please report this bug to the Tpetra developers.");
627 #endif // HAVE_TPETRACORE_MPI 652 template<
class PacketType,
653 class SendLayoutType,
654 class SendDeviceType,
655 class RecvLayoutType,
656 class RecvDeviceType,
661 template<
class PacketType,
662 class SendLayoutType,
663 class SendDeviceType,
664 class RecvLayoutType,
665 class RecvDeviceType>
672 typedef ::Kokkos::View<
const PacketType*,
674 SendDeviceType> send_buffer_type;
675 typedef ::Kokkos::View<PacketType*,
677 RecvDeviceType> recv_buffer_type;
679 static std::shared_ptr<CommRequest>
681 const recv_buffer_type& recvbuf,
682 const ::Teuchos::EReductionType op,
683 const ::Teuchos::Comm<int>& comm)
685 static_assert (! std::is_const<PacketType>::value,
686 "PacketType must be a nonconst type.");
687 static_assert (std::is_same<SendLayoutType, ::Kokkos::LayoutLeft>::value ||
688 std::is_same<SendLayoutType, ::Kokkos::LayoutRight>::value,
689 "SendLayoutType must be either Kokkos::LayoutLeft or " 690 "Kokkos::LayoutRight.");
691 static_assert (std::is_same<RecvLayoutType, ::Kokkos::LayoutLeft>::value ||
692 std::is_same<RecvLayoutType, ::Kokkos::LayoutRight>::value,
693 "RecvLayoutType must be either Kokkos::LayoutLeft or " 694 "Kokkos::LayoutRight.");
695 #ifdef HAVE_TPETRACORE_MPI 698 typedef typename std::remove_const<PacketType>::type packet_type;
700 std::shared_ptr<CommRequest> req =
701 Impl::iallreduceRaw<packet_type> (sendbuf.ptr_on_device (),
702 recvbuf.ptr_on_device (),
703 static_cast<int> (sendbuf.dimension_0 ()),
705 return Impl::wrapIallreduceCommRequest (req, sendbuf, recvbuf);
706 #else // NOT HAVE_TPETRACORE_MPI 713 return Impl::emptyCommRequest ();
714 #endif // HAVE_TPETRACORE_MPI 719 template<
class PacketType,
720 class SendLayoutType,
721 class SendDeviceType,
722 class RecvLayoutType,
723 class RecvDeviceType>
734 typedef ::Kokkos::View<
const PacketType,
736 SendDeviceType> send_buffer_type;
737 typedef ::Kokkos::View<PacketType,
739 RecvDeviceType> recv_buffer_type;
741 static std::shared_ptr<CommRequest>
743 const recv_buffer_type& recvbuf,
744 const ::Teuchos::EReductionType op,
745 const ::Teuchos::Comm<int>& comm)
747 static_assert (! std::is_const<PacketType>::value,
748 "PacketType must be a nonconst type.");
749 static_assert (std::is_same<SendLayoutType, ::Kokkos::LayoutLeft>::value ||
750 std::is_same<SendLayoutType, ::Kokkos::LayoutRight>::value,
751 "SendLayoutType must be either Kokkos::LayoutLeft or " 752 "Kokkos::LayoutRight.");
753 static_assert (std::is_same<RecvLayoutType, ::Kokkos::LayoutLeft>::value ||
754 std::is_same<RecvLayoutType, ::Kokkos::LayoutRight>::value,
755 "RecvLayoutType must be either Kokkos::LayoutLeft or " 756 "Kokkos::LayoutRight.");
757 #ifdef HAVE_TPETRACORE_MPI 760 typedef typename std::remove_const<PacketType>::type packet_type;
762 std::shared_ptr<CommRequest> req =
763 Impl::iallreduceRaw<packet_type> (sendbuf.ptr_on_device (),
764 recvbuf.ptr_on_device (),
765 static_cast<int> (1),
767 return Impl::wrapIallreduceCommRequest (req, sendbuf, recvbuf);
768 #else // NOT HAVE_TPETRACORE_MPI 775 return Impl::emptyCommRequest ();
776 #endif // HAVE_TPETRACORE_MPI 811 template<
class InputViewType,
class OutputViewType>
812 std::shared_ptr<CommRequest>
814 const OutputViewType& recvbuf,
815 const ::Teuchos::EReductionType op,
816 const ::Teuchos::Comm<int>& comm)
818 static_assert (Kokkos::Impl::is_view<InputViewType>::value,
819 "InputViewType must be a Kokkos::View specialization.");
820 static_assert (Kokkos::Impl::is_view<OutputViewType>::value,
821 "OutputViewType must be a Kokkos::View specialization.");
822 constexpr
int rank =
static_cast<int> (OutputViewType::rank);
823 static_assert (static_cast<int> (InputViewType::rank) == rank,
824 "InputViewType and OutputViewType must have the same rank.");
825 static_assert (rank == 0 || rank == 1,
826 "InputViewType and OutputViewType must both have " 827 "rank 0 or rank 1.");
828 typedef typename OutputViewType::non_const_value_type packet_type;
829 static_assert (std::is_same<
typename OutputViewType::value_type,
831 "OutputViewType must be a nonconst Kokkos::View.");
832 static_assert (std::is_same<
typename InputViewType::non_const_value_type,
834 "InputViewType and OutputViewType must be Views " 835 "whose entries have the same type.");
836 typedef typename InputViewType::array_layout send_layout_type;
837 typedef typename OutputViewType::array_layout recv_layout_type;
838 typedef typename InputViewType::device_type send_device_type;
839 typedef typename OutputViewType::device_type recv_device_type;
842 recv_layout_type, recv_device_type, rank> impl_type;
849 #endif // TPETRA_DETAILS_IALLREDUCE_HPP IallreduceCommRequest(const std::shared_ptr< CommRequest > &req, const send_buffer_type &sendbuf, const recv_buffer_type &recvbuf)
Constructor that takes a wrapped request (representing the pending MPI_Iallreduce operation itself)...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
std::shared_ptr< CommRequest > wrapIallreduceCommRequest(const std::shared_ptr< CommRequest > &req, const ::Kokkos::View< const PacketType *, SendLayoutType, SendDeviceType > &sendbuf, const ::Kokkos::View< PacketType *, RecvLayoutType, RecvDeviceType > &recvbuf)
Function for wrapping the CommRequest to be returned from Tpetra::Details::iallreduce; overload for r...
Add specializations of Teuchos::Details::MpiTypeTraits for Kokkos::complex<float> and Kokkos::complex...
void cancel()
Cancel the pending communication request.
::Kokkos::View< const PacketType, SendLayoutType, SendDeviceType > send_buffer_type
Type of the send buffer.
void wait()
Wait on this communication request to complete.
void deep_copy(MultiVector< DS, DL, DG, DN, dstClassic > &dst, const MultiVector< SS, SL, SG, SN, srcClassic > &src)
Copy the contents of the MultiVector src into dst.
Object representing a pending Tpetra::Details::iallreduce operation.
::Kokkos::View< const PacketType *, SendLayoutType, SendDeviceType > send_buffer_type
Type of the send buffer.
Implementation details of Tpetra.
virtual ~IallreduceCommRequest()
Destructor (virtual for memory safety).
::Kokkos::View< PacketType *, RecvLayoutType, RecvDeviceType > recv_buffer_type
Type of the receive buffer.
Implementation of Tpetra::Details::iallreduce.
Part of the Work-around for not having MPI >= 3.
void cancel()
Cancel the pending communication request.
IallreduceCommRequest()
Default constructor.
::Kokkos::View< PacketType, RecvLayoutType, RecvDeviceType > recv_buffer_type
Type of the receive buffer.
IallreduceCommRequest(const std::shared_ptr< CommRequest > &req, const send_buffer_type &sendbuf, const recv_buffer_type &recvbuf)
Constructor that takes a wrapped request (representing the pending MPI_Iallreduce operation itself)...
virtual ~IallreduceCommRequest()
Destructor (virtual for memory safety).
void wait()
Wait on this communication request to complete.
Base class for the request (more or less a future) representing a pending nonblocking MPI operation...
std::shared_ptr< CommRequest > iallreduce(const InputViewType &sendbuf, const OutputViewType &recvbuf, const ::Teuchos::EReductionType op, const ::Teuchos::Comm< int > &comm)
Nonblocking all-reduce, for either rank-1 or rank-0 Kokkos::View objects.
std::shared_ptr< CommRequest > iallreduceRaw(const Packet sendbuf[], Packet recvbuf[], const int count, const ::Teuchos::EReductionType op, const ::Teuchos::Comm< int > &comm)
Second lowest-level implementation of Tpetra::Details::iallreduce (see bottom of this header file)...
IallreduceCommRequest()
Default constructor.
virtual ~CommRequest()
Destructor (virtual for memory safety of derived classes).