88
99#include < KokkosComm/concepts.hpp>
1010#include < KokkosComm/traits.hpp>
11+ #include " mpi_space.hpp"
12+ #include " req.hpp"
1113
1214#include " impl/pack_traits.hpp"
1315#include " impl/types.hpp"
1416#include " impl/error_handling.hpp"
1517
16- namespace KokkosComm ::Impl {
18+ namespace KokkosComm ::mpi {
19+
20+ template <KokkosExecutionSpace ExecSpace, KokkosView SView, KokkosView RView>
21+ auto ialltoall (const ExecSpace &space, const SView sv, RView rv, int count, MPI_Comm comm) -> Req<Mpi> {
22+ using ST = typename SView::non_const_value_type;
23+ using RT = typename RView::non_const_value_type;
24+ static_assert (std::is_same_v<ST, RT>, " KokkosComm::mpi::ialltoall: View value types must be identical" );
25+ Kokkos::Tools::pushRegion (" KokkosComm::mpi::ialltoall" );
26+
27+ fail_if (!is_contiguous (sv) || !is_contiguous (rv),
28+ " KokkosComm::mpi::ialltoall: unimplemented for non-contiguous views" );
29+
30+ // Sync: Work in space may have been used to produce view data.
31+ space.fence (" fence before non-blocking all-gather" );
32+
33+ Req<Mpi> req;
34+ // All ranks send/recv same count
35+ MPI_Ialltoall (data_handle (sv), count, Impl::mpi_type_v<ST>, data_handle (rv), count, Impl::mpi_type_v<RT>, comm,
36+ &req.mpi_request ());
37+ req.extend_view_lifetime (sv);
38+ req.extend_view_lifetime (rv);
39+
40+ Kokkos::Tools::popRegion ();
41+ return req;
42+ }
1743
1844template <KokkosExecutionSpace ExecSpace, KokkosView SendView, KokkosView RecvView>
1945void alltoall (const ExecSpace &space, const SendView &sv, const size_t sendCount, const RecvView &rv,
2046 const size_t recvCount, MPI_Comm comm) {
21- Kokkos::Tools::pushRegion (" KokkosComm::Impl ::alltoall" );
47+ Kokkos::Tools::pushRegion (" KokkosComm::mpi ::alltoall" );
2248
2349 using SendScalar = typename SendView::value_type;
2450 using RecvScalar = typename RecvView::value_type;
@@ -27,7 +53,7 @@ void alltoall(const ExecSpace &space, const SendView &sv, const size_t sendCount
2753 static_assert (KokkosComm::rank<RecvView>() <= 1 , " alltoall for RecvView::rank > 1 not supported" );
2854
2955 // Make sure views are ready
30- space.fence (" KokkosComm::Impl ::alltoall" );
56+ space.fence (" KokkosComm::mpi ::alltoall" );
3157
3258 KokkosComm::mpi::fail_if (!KokkosComm::is_contiguous (sv) || !KokkosComm::is_contiguous (rv),
3359 " alltoall for non-contiguous views not implemented" );
@@ -48,23 +74,23 @@ void alltoall(const ExecSpace &space, const SendView &sv, const size_t sendCount
4874 KokkosComm::mpi::fail_if (true , ss.str ().data ());
4975 }
5076
51- MPI_Alltoall (KokkosComm::data_handle (sv), sendCount, mpi_type_v<SendScalar>, KokkosComm::data_handle (rv), recvCount ,
52- mpi_type_v<RecvScalar>, comm);
77+ MPI_Alltoall (KokkosComm::data_handle (sv), sendCount, Impl:: mpi_type_v<SendScalar>, KokkosComm::data_handle (rv),
78+ recvCount, Impl:: mpi_type_v<RecvScalar>, comm);
5379
5480 Kokkos::Tools::popRegion ();
5581}
5682
5783// in-place alltoall
5884template <KokkosExecutionSpace ExecSpace, KokkosView RecvView>
5985void alltoall (const ExecSpace &space, const RecvView &rv, const size_t recvCount, MPI_Comm comm) {
60- Kokkos::Tools::pushRegion (" KokkosComm::Impl ::alltoall" );
86+ Kokkos::Tools::pushRegion (" KokkosComm::mpi ::alltoall" );
6187
6288 using RecvScalar = typename RecvView::value_type;
6389
6490 static_assert (RecvView::rank <= 1 , " alltoall for RecvView::rank > 1 not supported" );
6591
6692 // Make sure views are ready
67- space.fence (" KokkosComm::Impl ::alltoall" );
93+ space.fence (" KokkosComm::mpi ::alltoall" );
6894
6995 KokkosComm::mpi::fail_if (!KokkosComm::is_contiguous (rv), " alltoall for non-contiguous views not implemented" );
7096
@@ -79,9 +105,9 @@ void alltoall(const ExecSpace &space, const RecvView &rv, const size_t recvCount
79105 }
80106
81107 MPI_Alltoall (MPI_IN_PLACE, 0 /* ignored*/ , MPI_BYTE /* ignored*/ , KokkosComm::data_handle (rv), recvCount,
82- mpi_type_v<RecvScalar>, comm);
108+ Impl:: mpi_type_v<RecvScalar>, comm);
83109
84110 Kokkos::Tools::popRegion ();
85111}
86112
87- } // namespace KokkosComm::Impl
113+ } // namespace KokkosComm::mpi
0 commit comments