From 8e2a12a1d20613e0fa07b2c3ab5c5161d6e8f5aa Mon Sep 17 00:00:00 2001 From: Marcel Koch Date: Wed, 30 Oct 2024 16:09:06 +0100 Subject: [PATCH] [coll-comm] remove envelop-based constructors --- core/distributed/dense_communicator.cpp | 22 ++----- .../distributed/neighborhood_communicator.cpp | 27 +++----- .../mpi/distributed/dense_communicator.cpp | 62 ------------------- .../distributed/neighborhood_communicator.cpp | 43 ------------- .../core/distributed/dense_communicator.hpp | 26 ++------ .../distributed/neighborhood_communicator.hpp | 20 ------ 6 files changed, 17 insertions(+), 183 deletions(-) diff --git a/core/distributed/dense_communicator.cpp b/core/distributed/dense_communicator.cpp index 10d5067ee5c..46405ce8648 100644 --- a/core/distributed/dense_communicator.cpp +++ b/core/distributed/dense_communicator.cpp @@ -93,20 +93,6 @@ DenseCommunicator& DenseCommunicator::operator=(DenseCommunicator&& other) } -DenseCommunicator::DenseCommunicator( - communicator base, const std::vector& recv_sizes, - const std::vector& recv_offsets, - const std::vector& send_sizes, - const std::vector& send_offsets) - : CollectiveCommunicator(base), - comm_(base), - recv_sizes_(recv_sizes), - recv_offsets_(recv_offsets), - send_sizes_(send_sizes), - send_offsets_(send_offsets) -{} - - request DenseCommunicator::i_all_to_all_v_impl( std::shared_ptr exec, const void* send_buffer, MPI_Datatype send_type, void* recv_buffer, MPI_Datatype recv_type) const @@ -139,8 +125,12 @@ DenseCommunicator::create_with_same_type( std::unique_ptr DenseCommunicator::create_inverse() const { - return std::make_unique( - comm_, send_sizes_, send_offsets_, recv_sizes_, recv_offsets_); + auto inv = std::make_unique(comm_); + inv->send_sizes_ = recv_sizes_; + inv->send_offsets_ = recv_offsets_; + inv->recv_sizes_ = send_sizes_; + inv->recv_offsets_ = send_offsets_; + return inv; } diff --git a/core/distributed/neighborhood_communicator.cpp b/core/distributed/neighborhood_communicator.cpp index 66aeffb508d..287595f5b15 100644 --- a/core/distributed/neighborhood_communicator.cpp +++ b/core/distributed/neighborhood_communicator.cpp @@ -101,9 +101,13 @@ NeighborhoodCommunicator::create_inverse() const comm_.get(), num_sources, sources.data(), MPI_UNWEIGHTED, num_destinations, destinations.data(), MPI_UNWEIGHTED)); - return std::make_unique( - base_comm, destinations, send_sizes_, send_offsets_, sources, - recv_sizes_, recv_offsets_); + auto inv = std::make_unique(base_comm); + inv->comm_ = create_neighborhood_comm(base_comm, destinations, sources); + inv->send_sizes_ = recv_sizes_; + inv->send_offsets_ = recv_offsets_; + inv->recv_sizes_ = send_sizes_; + inv->recv_offsets_ = send_offsets_; + return inv; } @@ -119,23 +123,6 @@ comm_index_type NeighborhoodCommunicator::get_send_size() const } -NeighborhoodCommunicator::NeighborhoodCommunicator( - communicator base, const std::vector& sources, - const std::vector& recv_sizes, - const std::vector& recv_offsets, - const std::vector& destinations, - const std::vector& send_sizes, - const std::vector& send_offsets) - : CollectiveCommunicator(base), comm_(MPI_COMM_NULL) -{ - comm_ = create_neighborhood_comm(base, sources, destinations); - send_sizes_ = send_sizes; - send_offsets_ = send_offsets; - recv_sizes_ = recv_sizes; - recv_offsets_ = recv_offsets; -} - - NeighborhoodCommunicator::NeighborhoodCommunicator(communicator base) : CollectiveCommunicator(std::move(base)), comm_(MPI_COMM_NULL), diff --git a/core/test/mpi/distributed/dense_communicator.cpp b/core/test/mpi/distributed/dense_communicator.cpp index 7e80993f441..c273814cd04 100644 --- a/core/test/mpi/distributed/dense_communicator.cpp +++ b/core/test/mpi/distributed/dense_communicator.cpp @@ -69,52 +69,6 @@ TEST_F(DenseCommunicator, CanConstructFromIndexMap) } -TEST_F(DenseCommunicator, CanConstructFromEnvelopData) -{ - // clang-format off - std::vector recv_sizes[] = { - {0, 2, 2, - 0, 0, 0}, - {2, 0, 1, - 2, 0, 0}, - {0, 2, 0, - 0, 0, 1}, - {2, 0, 0, - 0, 2, 0}, - {0, 2, 0, - 2, 0, 2}, - {0, 0, 1, - 0, 3, 0}}; - std::vector send_sizes[] = { - {0, 2, 0, - 2, 0, 0}, - {2, 0, 2, - 0, 2, 0}, - {0, 1, 0, - 0, 0, 1}, - {2, 0, 0, - 0, 2, 0}, - {0, 2, 0, - 2, 0, 3}, - {0, 0, 1, - 0, 2, 0}}; - // clang-format on - std::vector recv_offsets(recv_sizes[rank].size() + 1); - std::vector send_offsets(send_sizes[rank].size() + 1); - std::partial_sum(recv_sizes[rank].begin(), recv_sizes[rank].end(), - recv_offsets.begin() + 1); - std::partial_sum(send_sizes[rank].begin(), send_sizes[rank].end(), - send_offsets.begin() + 1); - - gko::experimental::mpi::DenseCommunicator dcomm{ - comm, recv_sizes[rank], recv_offsets, send_sizes[rank], send_offsets, - }; - - ASSERT_EQ(dcomm.get_recv_size(), recv_offsets.back()); - ASSERT_EQ(dcomm.get_send_size(), send_offsets.back()); -} - - TEST_F(DenseCommunicator, CanConstructFromEmptyIndexMap) { auto imap = map_type{ref}; @@ -139,22 +93,6 @@ TEST_F(DenseCommunicator, CanConstructFromIndexMapWithoutConnection) } -TEST_F(DenseCommunicator, CanConstructFromEmptyEnvelopData) -{ - std::vector recv_sizes; - std::vector send_sizes; - std::vector recv_offsets{0}; - std::vector send_offsets{0}; - - gko::experimental::mpi::DenseCommunicator dcomm{ - comm, recv_sizes, recv_offsets, send_sizes, send_offsets, - }; - - ASSERT_EQ(dcomm.get_recv_size(), 0); - ASSERT_EQ(dcomm.get_send_size(), 0); -} - - TEST_F(DenseCommunicator, CanTestEquality) { auto comm_a = create_default_comm(); diff --git a/core/test/mpi/distributed/neighborhood_communicator.cpp b/core/test/mpi/distributed/neighborhood_communicator.cpp index b89ae53b087..11afd9f083b 100644 --- a/core/test/mpi/distributed/neighborhood_communicator.cpp +++ b/core/test/mpi/distributed/neighborhood_communicator.cpp @@ -68,31 +68,6 @@ TEST_F(NeighborhoodCommunicator, CanConstructFromIndexMap) } -TEST_F(NeighborhoodCommunicator, CanConstructFromEnvelopData) -{ - std::vector sources[] = {{1, 2}, {0, 2, 4}, {1, 5}, - {0, 4}, {1, 3, 5}, {2, 4}}; - std::vector recv_sizes[] = {{2, 2}, {2, 1, 2}, {2, 1}, - {2, 2}, {2, 2, 2}, {1, 3}}; - std::vector destinations = sources[rank]; - std::vector send_sizes[] = {{2, 2}, {2, 2, 2}, {1, 1}, - {2, 2}, {2, 2, 3}, {1, 2}}; - std::vector recv_offsets(recv_sizes[rank].size() + 1); - std::vector send_offsets(send_sizes[rank].size() + 1); - std::partial_sum(recv_sizes[rank].begin(), recv_sizes[rank].end(), - recv_offsets.begin() + 1); - std::partial_sum(send_sizes[rank].begin(), send_sizes[rank].end(), - send_offsets.begin() + 1); - - gko::experimental::mpi::NeighborhoodCommunicator spcomm{ - comm, sources[rank], recv_sizes[rank], recv_offsets, - destinations, send_sizes[rank], send_offsets}; - - ASSERT_EQ(spcomm.get_recv_size(), recv_offsets.back()); - ASSERT_EQ(spcomm.get_send_size(), send_offsets.back()); -} - - TEST_F(NeighborhoodCommunicator, CanConstructFromEmptyIndexMap) { auto imap = map_type{ref}; @@ -117,24 +92,6 @@ TEST_F(NeighborhoodCommunicator, CanConstructFromIndexMapWithoutConnection) } -TEST_F(NeighborhoodCommunicator, CanConstructFromEmptyEnvelopData) -{ - std::vector sources; - std::vector recv_sizes; - std::vector destinations; - std::vector send_sizes; - std::vector recv_offsets{0}; - std::vector send_offsets{0}; - - gko::experimental::mpi::NeighborhoodCommunicator spcomm{ - comm, sources, send_sizes, send_offsets, - destinations, recv_sizes, recv_offsets}; - - ASSERT_EQ(spcomm.get_recv_size(), 0); - ASSERT_EQ(spcomm.get_send_size(), 0); -} - - TEST_F(NeighborhoodCommunicator, CanTestEquality) { auto comm_a = create_default_comm(); diff --git a/include/ginkgo/core/distributed/dense_communicator.hpp b/include/ginkgo/core/distributed/dense_communicator.hpp index 4c211faf977..99975e1b661 100644 --- a/include/ginkgo/core/distributed/dense_communicator.hpp +++ b/include/ginkgo/core/distributed/dense_communicator.hpp @@ -61,24 +61,6 @@ class DenseCommunicator final : public CollectiveCommunicator { communicator base, const distributed::index_map& imap); - /** - * Create a DenseCommunicator by explicitly defining the - * neighborhood lists and sizes/offsets. - * - * @param base the base communicator - * @param sources the ranks to receive from - * @param recv_sizes the number of elements to recv for each source - * @param recv_offsets the offset for each source - * @param destinations the ranks to send to - * @param send_sizes the number of elements to send for each destination - * @param send_offsets the offset for each destination - */ - DenseCommunicator(communicator base, - const std::vector& recv_sizes, - const std::vector& recv_offsets, - const std::vector& send_sizes, - const std::vector& send_offsets); - /** * @copydoc collective_communicator::create_with_same_type */ @@ -141,10 +123,10 @@ class DenseCommunicator final : public CollectiveCommunicator { private: communicator comm_; - std::vector send_sizes_; - std::vector send_offsets_; - std::vector recv_sizes_; - std::vector recv_offsets_; + std::vector send_sizes_; + std::vector send_offsets_; + std::vector recv_sizes_; + std::vector recv_offsets_; }; diff --git a/include/ginkgo/core/distributed/neighborhood_communicator.hpp b/include/ginkgo/core/distributed/neighborhood_communicator.hpp index e7c9f763c48..7b4bb50fd1e 100644 --- a/include/ginkgo/core/distributed/neighborhood_communicator.hpp +++ b/include/ginkgo/core/distributed/neighborhood_communicator.hpp @@ -65,26 +65,6 @@ class NeighborhoodCommunicator final : public CollectiveCommunicator { communicator base, const distributed::index_map& imap); - /** - * Create a NeighborhoodCommunicator by explicitly defining the - * neighborhood lists and sizes/offsets. - * - * @param base the base communicator - * @param sources the ranks to receive from - * @param recv_sizes the number of elements to recv for each source - * @param recv_offsets the offset for each source - * @param destinations the ranks to send to - * @param send_sizes the number of elements to send for each destination - * @param send_offsets the offset for each destination - */ - NeighborhoodCommunicator(communicator base, - const std::vector& sources, - const std::vector& recv_sizes, - const std::vector& recv_offsets, - const std::vector& destinations, - const std::vector& send_sizes, - const std::vector& send_offsets); - /** * @copydoc collective_communicator::create_with_same_type */