diff --git a/core/distributed/device_partition.hpp b/core/distributed/device_partition.hpp index ba91019603f..e9c6cc255c6 100644 --- a/core/distributed/device_partition.hpp +++ b/core/distributed/device_partition.hpp @@ -2,8 +2,8 @@ // // SPDX-License-Identifier: BSD-3-Clause -#ifndef GINKGO_PARTITION_HPP -#define GINKGO_PARTITION_HPP +#ifndef GKO_CORE_DISTRIBUTED_PARTITION_HPP +#define GKO_CORE_DISTRIBUTED_PARTITION_HPP #include @@ -89,4 +89,4 @@ to_device_const( } // namespace gko -#endif // GINKGO_PARTITION_HPP +#endif // GKO_CORE_DISTRIBUTED_PARTITION_HPP diff --git a/core/distributed/neighborhood_communicator.cpp b/core/distributed/neighborhood_communicator.cpp index fb126ab79a3..51d5352b1a9 100644 --- a/core/distributed/neighborhood_communicator.cpp +++ b/core/distributed/neighborhood_communicator.cpp @@ -84,8 +84,9 @@ mpi::communicator create_neighborhood_comm( base.force_host_buffer()); } -std::unique_ptr -neighborhood_communicator::create_inverse() const + +std::unique_ptr +NeighborhoodCommunicator::create_inverse() const { auto base_comm = this->get_base_communicator(); distributed::comm_index_type num_sources; @@ -100,33 +101,32 @@ neighborhood_communicator::create_inverse() const comm_.get(), num_sources, sources.data(), MPI_UNWEIGHTED, num_destinations, destinations.data(), MPI_UNWEIGHTED)); - return std::unique_ptr{ - new neighborhood_communicator(base_comm, destinations, recv_sizes_, - recv_offsets_, sources, send_sizes_, - send_offsets_)}; + return std::unique_ptr{new NeighborhoodCommunicator( + base_comm, destinations, recv_sizes_, recv_offsets_, sources, + send_sizes_, send_offsets_)}; } -comm_index_type neighborhood_communicator::get_recv_size() const +comm_index_type NeighborhoodCommunicator::get_recv_size() const { return recv_offsets_.back(); } -comm_index_type neighborhood_communicator::get_send_size() const +comm_index_type NeighborhoodCommunicator::get_send_size() const { return send_offsets_.back(); } -neighborhood_communicator::neighborhood_communicator( +NeighborhoodCommunicator::NeighborhoodCommunicator( communicator base, const std::vector& sources, const std::vector& send_sizes, const std::vector& send_offsets, const std::vector& destinations, const std::vector& recv_sizes, const std::vector& recv_offsets) - : collective_communicator(base), comm_(MPI_COMM_NULL) + : CollectiveCommunicator(base), comm_(MPI_COMM_NULL) { comm_ = create_neighborhood_comm(base, sources, destinations); send_sizes_ = send_sizes; @@ -136,8 +136,8 @@ neighborhood_communicator::neighborhood_communicator( } -neighborhood_communicator::neighborhood_communicator(communicator base) - : collective_communicator(std::move(base)), +NeighborhoodCommunicator::NeighborhoodCommunicator(communicator base) + : CollectiveCommunicator(std::move(base)), comm_(MPI_COMM_SELF), send_sizes_(), send_offsets_(1), @@ -152,7 +152,7 @@ neighborhood_communicator::neighborhood_communicator(communicator base) } -request neighborhood_communicator::i_all_to_all_v( +request NeighborhoodCommunicator::i_all_to_all_v( std::shared_ptr exec, const void* send_buffer, MPI_Datatype send_type, void* recv_buffer, MPI_Datatype recv_type) const { @@ -166,24 +166,24 @@ request neighborhood_communicator::i_all_to_all_v( } -std::unique_ptr -neighborhood_communicator::create_with_same_type( +std::unique_ptr +NeighborhoodCommunicator::create_with_same_type( communicator base, const distributed::index_map_variant& imap) const { return std::visit( [base](const auto& imap) { - return std::unique_ptr( - new neighborhood_communicator(base, imap)); + return std::unique_ptr( + new NeighborhoodCommunicator(base, imap)); }, imap); } template -neighborhood_communicator::neighborhood_communicator( +NeighborhoodCommunicator::NeighborhoodCommunicator( communicator base, const distributed::index_map& imap) - : collective_communicator(base), + : CollectiveCommunicator(base), comm_(MPI_COMM_SELF), recv_sizes_(imap.get_remote_target_ids().get_size()), recv_offsets_(recv_sizes_.size() + 1), @@ -225,7 +225,7 @@ neighborhood_communicator::neighborhood_communicator( #define GKO_DECLARE_NEIGHBORHOOD_CONSTRUCTOR(LocalIndexType, GlobalIndexType) \ - neighborhood_communicator::neighborhood_communicator( \ + NeighborhoodCommunicator::NeighborhoodCommunicator( \ communicator base, \ const distributed::index_map& imap) diff --git a/core/test/mpi/distributed/neighborhood_communicator.cpp b/core/test/mpi/distributed/neighborhood_communicator.cpp index 1432ea07f4e..cbea0af058e 100644 --- a/core/test/mpi/distributed/neighborhood_communicator.cpp +++ b/core/test/mpi/distributed/neighborhood_communicator.cpp @@ -25,7 +25,7 @@ class NeighborhoodCommunicator : public ::testing::Test { TEST_F(NeighborhoodCommunicator, CanDefaultConstruct) { - gko::experimental::mpi::neighborhood_communicator nhcomm{comm}; + gko::experimental::mpi::NeighborhoodCommunicator nhcomm{comm}; ASSERT_EQ(nhcomm.get_base_communicator(), comm); ASSERT_EQ(nhcomm.get_send_size(), 0); @@ -45,7 +45,7 @@ TEST_F(NeighborhoodCommunicator, CanConstructFromIndexMap) {ref, {8, 12, 13, 14}}}; auto imap = map_type{ref, part, comm.rank(), recv_connections[rank]}; - gko::experimental::mpi::neighborhood_communicator spcomm{comm, imap}; + gko::experimental::mpi::NeighborhoodCommunicator spcomm{comm, imap}; std::array send_sizes = {4, 6, 2, 4, 7, 3}; ASSERT_EQ(spcomm.get_recv_size(), recv_connections[rank].get_size()); @@ -69,7 +69,7 @@ TEST_F(NeighborhoodCommunicator, CanConstructFromEnvelopData) std::partial_sum(send_sizes[rank].begin(), send_sizes[rank].end(), send_offsets.begin() + 1); - gko::experimental::mpi::neighborhood_communicator spcomm{ + gko::experimental::mpi::NeighborhoodCommunicator spcomm{ comm, sources[rank], send_sizes[rank], send_offsets, destinations, recv_sizes[rank], recv_offsets}; @@ -82,7 +82,7 @@ TEST_F(NeighborhoodCommunicator, CanConstructFromEmptyIndexMap) { auto imap = map_type{ref}; - gko::experimental::mpi::neighborhood_communicator spcomm{comm, imap}; + gko::experimental::mpi::NeighborhoodCommunicator spcomm{comm, imap}; ASSERT_EQ(spcomm.get_recv_size(), 0); ASSERT_EQ(spcomm.get_send_size(), 0); @@ -95,7 +95,7 @@ TEST_F(NeighborhoodCommunicator, CanConstructFromIndexMapWithoutConnection) ref, comm.size(), comm.size() * 3)); auto imap = map_type{ref, part, comm.rank(), {ref, 0}}; - gko::experimental::mpi::neighborhood_communicator spcomm{comm, imap}; + gko::experimental::mpi::NeighborhoodCommunicator spcomm{comm, imap}; ASSERT_EQ(spcomm.get_recv_size(), 0); ASSERT_EQ(spcomm.get_send_size(), 0); @@ -111,7 +111,7 @@ TEST_F(NeighborhoodCommunicator, CanConstructFromEmptyEnvelopData) std::vector recv_offsets{0}; std::vector send_offsets{0}; - gko::experimental::mpi::neighborhood_communicator spcomm{ + gko::experimental::mpi::NeighborhoodCommunicator spcomm{ comm, sources, send_sizes, send_offsets, destinations, recv_sizes, recv_offsets}; @@ -131,7 +131,7 @@ TEST_F(NeighborhoodCommunicator, CanCommunicateIalltoall) {ref, {4, 5, 9, 10, 16, 15}}, {ref, {8, 12, 13, 14}}}; auto imap = map_type{ref, part, comm.rank(), recv_connections[rank]}; - gko::experimental::mpi::neighborhood_communicator spcomm{comm, imap}; + gko::experimental::mpi::NeighborhoodCommunicator spcomm{comm, imap}; gko::array recv_buffer{ref, recv_connections[rank].get_size()}; gko::array send_buffers[] = {{ref, {0, 1, 1, 2}}, {ref, {3, 5, 3, 4, 4, 5}}, @@ -150,7 +150,7 @@ TEST_F(NeighborhoodCommunicator, CanCommunicateIalltoall) TEST_F(NeighborhoodCommunicator, CanCommunicateIalltoallWhenEmpty) { - gko::experimental::mpi::neighborhood_communicator spcomm{comm}; + gko::experimental::mpi::NeighborhoodCommunicator spcomm{comm}; auto req = spcomm.i_all_to_all_v(ref, static_cast(nullptr), static_cast(nullptr)); @@ -169,7 +169,7 @@ TEST_F(NeighborhoodCommunicator, CanCreateInverse) {ref, {4, 5, 9, 10, 16, 15}}, {ref, {8, 12, 13, 14}}}; auto imap = map_type{ref, part, comm.rank(), recv_connections[rank]}; - gko::experimental::mpi::neighborhood_communicator spcomm{comm, imap}; + gko::experimental::mpi::NeighborhoodCommunicator spcomm{comm, imap}; auto inverse = spcomm.create_inverse(); @@ -189,7 +189,7 @@ TEST_F(NeighborhoodCommunicator, CanCommunicateRoundTrip) {ref, {4, 5, 9, 10, 16, 15}}, {ref, {8, 12, 13, 14}}}; auto imap = map_type{ref, part, comm.rank(), recv_connections[rank]}; - gko::experimental::mpi::neighborhood_communicator spcomm{comm, imap}; + gko::experimental::mpi::NeighborhoodCommunicator spcomm{comm, imap}; auto inverse = spcomm.create_inverse(); gko::array send_buffers[] = {{ref, {1, 2, 3, 4}}, {ref, {5, 6, 7, 8, 9, 10}}, diff --git a/include/ginkgo/core/base/types.hpp b/include/ginkgo/core/base/types.hpp index 6d8e2f3e928..3783d2c4b41 100644 --- a/include/ginkgo/core/base/types.hpp +++ b/include/ginkgo/core/base/types.hpp @@ -813,7 +813,7 @@ namespace distributed { /** - * Make mpi::comm_index_type avaiable in this namespace + * Make mpi::comm_index_type available in this namespace */ using mpi::comm_index_type; diff --git a/include/ginkgo/core/distributed/collective_communicator.hpp b/include/ginkgo/core/distributed/collective_communicator.hpp index d66bf0cd4c6..c6a26a5a8fa 100644 --- a/include/ginkgo/core/distributed/collective_communicator.hpp +++ b/include/ginkgo/core/distributed/collective_communicator.hpp @@ -25,11 +25,11 @@ namespace mpi { * A collective communicator only provides routines for collective * communications. At the moment this is restricted to the variable all-to-all. */ -class collective_communicator { +class CollectiveCommunicator { public: - virtual ~collective_communicator() = default; + virtual ~CollectiveCommunicator() = default; - explicit collective_communicator(communicator base = MPI_COMM_NULL) + explicit CollectiveCommunicator(communicator base = MPI_COMM_NULL) : base_(std::move(base)) {} @@ -41,8 +41,9 @@ class collective_communicator { /** * Non-blocking all-to-all communication. * - * The send_buffer must have size get_send_size, and the recv_buffer - * must have size get_recv_size. + * The send_buffer must have allocated at least get_send_size number of + * elements, and the recv_buffer must have allocated at least get_recv_size + * number of elements. * * @tparam SendType the type of the elements to send * @tparam RecvType the type of the elements to receive @@ -78,7 +79,7 @@ class collective_communicator { * * @return a collective_communicator with the same dynamic type */ - [[nodiscard]] virtual std::unique_ptr + [[nodiscard]] virtual std::unique_ptr create_with_same_type(communicator base, const distributed::index_map_variant& imap) const = 0; @@ -89,7 +90,7 @@ class collective_communicator { * @return a collective_communicator with the inverse communication * pattern. */ - [[nodiscard]] virtual std::unique_ptr + [[nodiscard]] virtual std::unique_ptr create_inverse() const = 0; /** diff --git a/include/ginkgo/core/distributed/index_map_fwd.hpp b/include/ginkgo/core/distributed/index_map_fwd.hpp index 1d40a0008ec..425e06ca16a 100644 --- a/include/ginkgo/core/distributed/index_map_fwd.hpp +++ b/include/ginkgo/core/distributed/index_map_fwd.hpp @@ -2,8 +2,8 @@ // // SPDX-License-Identifier: BSD-3-Clause -#ifndef GINKGO_INDEX_MAP_FWD_HPP -#define GINKGO_INDEX_MAP_FWD_HPP +#ifndef GKO_PUBLIC_CORE_INDEX_MAP_FWD_HPP +#define GKO_PUBLIC_CORE_INDEX_MAP_FWD_HPP #include @@ -27,4 +27,4 @@ using index_map_variant = } // namespace experimental } // namespace gko -#endif // GINKGO_INDEX_MAP_FWD_HPP +#endif // GKO_PUBLIC_CORE_INDEX_MAP_FWD_HPP diff --git a/include/ginkgo/core/distributed/neighborhood_communicator.hpp b/include/ginkgo/core/distributed/neighborhood_communicator.hpp index e49123c6dbd..0de3d85c7b8 100644 --- a/include/ginkgo/core/distributed/neighborhood_communicator.hpp +++ b/include/ginkgo/core/distributed/neighborhood_communicator.hpp @@ -29,15 +29,15 @@ namespace mpi { * No communication with any ranks that is not in one of those lists will * take place. */ -class neighborhood_communicator final : public collective_communicator { +class NeighborhoodCommunicator final : public CollectiveCommunicator { public: - using collective_communicator::i_all_to_all_v; + using CollectiveCommunicator::i_all_to_all_v; /** * Default constructor with empty communication pattern * @param base the base communicator */ - explicit neighborhood_communicator(communicator base); + explicit NeighborhoodCommunicator(communicator base); /** * Create a neighborhood_communicator from an index map. @@ -52,7 +52,7 @@ class neighborhood_communicator final : public collective_communicator { * @param imap the index map that defines the communication pattern */ template - neighborhood_communicator( + NeighborhoodCommunicator( communicator base, const distributed::index_map& imap); @@ -68,7 +68,7 @@ class neighborhood_communicator final : public collective_communicator { * @param send_sizes the number of elements to send for each destination * @param send_offsets the offset for each destination */ - neighborhood_communicator( + NeighborhoodCommunicator( communicator base, const std::vector& sources, const std::vector& recv_sizes, @@ -78,43 +78,38 @@ class neighborhood_communicator final : public collective_communicator { const std::vector& send_offsets); /** - * Communicate data from all ranks to all other ranks using the - * neighboorhood communication MPI_Ineighbor_alltoallv. See MPI - * documentation for more details + * @copydoc CollectiveCommunicator::i_all_to_all_v * - * @param exec The executor, on which the message buffers are located. - * @param send_buffer the buffer to send - * @param send_type the MPI_Datatype for the send buffer - * @param recv_buffer the buffer to gather into - * @param recv_type the MPI_Datatype for the recv buffer - * - * @return the request handle for the call + * This implementation uses the neighborhood communication + * MPI_Ineighbor_alltoallv. See MPI documentation for more details. */ request i_all_to_all_v(std::shared_ptr exec, const void* send_buffer, MPI_Datatype send_type, void* recv_buffer, MPI_Datatype recv_type) const override; - std::unique_ptr create_with_same_type( + [[nodiscard]] std::unique_ptr create_with_same_type( communicator base, const distributed::index_map_variant& imap) const override; + /** * Creates the inverse neighborhood_communicator by switching sources * and destinations. * * @return collective_communicator with the inverse communication pattern */ - std::unique_ptr create_inverse() const override; + [[nodiscard]] std::unique_ptr create_inverse() + const override; /** * @copydoc collective_communicator::get_recv_size */ - comm_index_type get_recv_size() const override; + [[nodiscard]] comm_index_type get_recv_size() const override; /** * @copydoc collective_communicator::get_recv_size */ - comm_index_type get_send_size() const override; + [[nodiscard]] comm_index_type get_send_size() const override; private: communicator comm_;