2424
2525#include " impl/pack_traits.hpp"
2626#include " impl/types.hpp"
27+ #include " impl/error_handling.hpp"
2728
2829namespace KokkosComm ::Impl {
2930
@@ -41,28 +42,27 @@ void alltoall(const ExecSpace &space, const SendView &sv, const size_t sendCount
4142 // Make sure views are ready
4243 space.fence (" KokkosComm::Impl::alltoall" );
4344
44- if (!KokkosComm::is_contiguous (sv) || !KokkosComm::is_contiguous (rv)) {
45- throw std::runtime_error (" alltoall for non-contiguous views not implemented" );
46- } else {
47- int size;
48- MPI_Comm_size (comm, &size);
49-
50- if (sendCount * size > KokkosComm::extent (sv, 0 )) {
51- std::stringstream ss;
52- ss << " alltoall sendCount * communicator size (" << sendCount << " * " << size
53- << " ) is greater than send view size" ;
54- throw std::runtime_error (ss.str ());
55- }
56- if (recvCount * size > KokkosComm::extent (rv, 0 )) {
57- std::stringstream ss;
58- ss << " alltoall recvCount * communicator size (" << recvCount << " * " << size
59- << " ) is greater than recv view size" ;
60- throw std::runtime_error (ss.str ());
61- }
62-
63- MPI_Alltoall (KokkosComm::data_handle (sv), sendCount, mpi_type_v<SendScalar>, KokkosComm::data_handle (rv), recvCount,
64- mpi_type_v<RecvScalar>, comm);
45+ KokkosComm::mpi::fail_if (!KokkosComm::is_contiguous (sv) || !KokkosComm::is_contiguous (rv),
46+ " alltoall for non-contiguous views not implemented" );
47+
48+ int size;
49+ MPI_Comm_size (comm, &size);
50+
51+ if (sendCount * size > KokkosComm::extent (sv, 0 )) {
52+ std::stringstream ss;
53+ ss << " alltoall sendCount * communicator size (" << sendCount << " * " << size
54+ << " ) is greater than send view size" ;
55+ KokkosComm::mpi::fail_if (true , ss.str ().data ());
6556 }
57+ if (recvCount * size > KokkosComm::extent (rv, 0 )) {
58+ std::stringstream ss;
59+ ss << " alltoall recvCount * communicator size (" << recvCount << " * " << size
60+ << " ) is greater than recv view size" ;
61+ KokkosComm::mpi::fail_if (true , ss.str ().data ());
62+ }
63+
64+ MPI_Alltoall (KokkosComm::data_handle (sv), sendCount, mpi_type_v<SendScalar>, KokkosComm::data_handle (rv), recvCount,
65+ mpi_type_v<RecvScalar>, comm);
6666
6767 Kokkos::Tools::popRegion ();
6868}
@@ -79,23 +79,21 @@ void alltoall(const ExecSpace &space, const RecvView &rv, const size_t recvCount
7979 // Make sure views are ready
8080 space.fence (" KokkosComm::Impl::alltoall" );
8181
82- if (!KokkosComm::is_contiguous (rv)) {
83- throw std::runtime_error (" alltoall for non-contiguous views not implemented" );
84- } else {
85- int size;
86- MPI_Comm_size (comm, &size);
87-
88- if (recvCount * size > KokkosComm::extent (rv, 0 )) {
89- std::stringstream ss;
90- ss << " alltoall recvCount * communicator size (" << recvCount << " * " << size
91- << " ) is greater than recv view size" ;
92- throw std::runtime_error (ss.str ());
93- }
94-
95- MPI_Alltoall (MPI_IN_PLACE, 0 /* ignored*/ , MPI_BYTE /* ignored*/ , KokkosComm::data_handle (rv), recvCount,
96- mpi_type_v<RecvScalar>, comm);
82+ KokkosComm::mpi::fail_if (!KokkosComm::is_contiguous (rv), " alltoall for non-contiguous views not implemented" );
83+
84+ int size;
85+ MPI_Comm_size (comm, &size);
86+
87+ if (recvCount * size > KokkosComm::extent (rv, 0 )) {
88+ std::stringstream ss;
89+ ss << " alltoall recvCount * communicator size (" << recvCount << " * " << size
90+ << " ) is greater than recv view size" ;
91+ KokkosComm::mpi::fail_if (true , ss.str ().data ());
9792 }
9893
94+ MPI_Alltoall (MPI_IN_PLACE, 0 /* ignored*/ , MPI_BYTE /* ignored*/ , KokkosComm::data_handle (rv), recvCount,
95+ mpi_type_v<RecvScalar>, comm);
96+
9997 Kokkos::Tools::popRegion ();
10098}
10199
0 commit comments