Skip to content

Commit

Permalink
[coll-comm] remove envelop-based constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelKoch committed Oct 30, 2024
1 parent 785a865 commit e7d32a1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 183 deletions.
22 changes: 6 additions & 16 deletions core/distributed/dense_communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,6 @@ DenseCommunicator& DenseCommunicator::operator=(DenseCommunicator&& other)
}


DenseCommunicator::DenseCommunicator(
communicator base, const std::vector<comm_index_type>& recv_sizes,
const std::vector<comm_index_type>& recv_offsets,
const std::vector<comm_index_type>& send_sizes,
const std::vector<comm_index_type>& 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<const Executor> exec, const void* send_buffer,
MPI_Datatype send_type, void* recv_buffer, MPI_Datatype recv_type) const
Expand Down Expand Up @@ -139,8 +125,12 @@ DenseCommunicator::create_with_same_type(
std::unique_ptr<CollectiveCommunicator> DenseCommunicator::create_inverse()
const
{
return std::make_unique<DenseCommunicator>(
comm_, send_sizes_, send_offsets_, recv_sizes_, recv_offsets_);
auto inv = std::make_unique<DenseCommunicator>(comm_);
inv->send_sizes_ = recv_sizes_;
inv->send_offsets_ = recv_offsets_;
inv->recv_sizes_ = send_sizes_;
inv->recv_offsets_ = send_offsets_;
return inv;
}


Expand Down
27 changes: 7 additions & 20 deletions core/distributed/neighborhood_communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<NeighborhoodCommunicator>(
base_comm, destinations, send_sizes_, send_offsets_, sources,
recv_sizes_, recv_offsets_);
auto inv = std::make_unique<NeighborhoodCommunicator>(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;
}


Expand All @@ -119,23 +123,6 @@ comm_index_type NeighborhoodCommunicator::get_send_size() const
}


NeighborhoodCommunicator::NeighborhoodCommunicator(
communicator base, const std::vector<comm_index_type>& sources,
const std::vector<comm_index_type>& recv_sizes,
const std::vector<comm_index_type>& recv_offsets,
const std::vector<comm_index_type>& destinations,
const std::vector<comm_index_type>& send_sizes,
const std::vector<comm_index_type>& 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),
Expand Down
62 changes: 0 additions & 62 deletions core/test/mpi/distributed/dense_communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,52 +69,6 @@ TEST_F(DenseCommunicator, CanConstructFromIndexMap)
}


TEST_F(DenseCommunicator, CanConstructFromEnvelopData)
{
// clang-format off
std::vector<comm_index_type> 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<comm_index_type> 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<comm_index_type> recv_offsets(recv_sizes[rank].size() + 1);
std::vector<comm_index_type> 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};
Expand All @@ -139,22 +93,6 @@ TEST_F(DenseCommunicator, CanConstructFromIndexMapWithoutConnection)
}


TEST_F(DenseCommunicator, CanConstructFromEmptyEnvelopData)
{
std::vector<comm_index_type> recv_sizes;
std::vector<comm_index_type> send_sizes;
std::vector<comm_index_type> recv_offsets{0};
std::vector<comm_index_type> 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();
Expand Down
43 changes: 0 additions & 43 deletions core/test/mpi/distributed/neighborhood_communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,6 @@ TEST_F(NeighborhoodCommunicator, CanConstructFromIndexMap)
}


TEST_F(NeighborhoodCommunicator, CanConstructFromEnvelopData)
{
std::vector<comm_index_type> sources[] = {{1, 2}, {0, 2, 4}, {1, 5},
{0, 4}, {1, 3, 5}, {2, 4}};
std::vector<comm_index_type> recv_sizes[] = {{2, 2}, {2, 1, 2}, {2, 1},
{2, 2}, {2, 2, 2}, {1, 3}};
std::vector<comm_index_type> destinations = sources[rank];
std::vector<comm_index_type> send_sizes[] = {{2, 2}, {2, 2, 2}, {1, 1},
{2, 2}, {2, 2, 3}, {1, 2}};
std::vector<comm_index_type> recv_offsets(recv_sizes[rank].size() + 1);
std::vector<comm_index_type> 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};
Expand All @@ -117,24 +92,6 @@ TEST_F(NeighborhoodCommunicator, CanConstructFromIndexMapWithoutConnection)
}


TEST_F(NeighborhoodCommunicator, CanConstructFromEmptyEnvelopData)
{
std::vector<comm_index_type> sources;
std::vector<comm_index_type> recv_sizes;
std::vector<comm_index_type> destinations;
std::vector<comm_index_type> send_sizes;
std::vector<comm_index_type> recv_offsets{0};
std::vector<comm_index_type> 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();
Expand Down
26 changes: 4 additions & 22 deletions include/ginkgo/core/distributed/dense_communicator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,6 @@ class DenseCommunicator final : public CollectiveCommunicator {
communicator base,
const distributed::index_map<LocalIndexType, GlobalIndexType>& 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<comm_index_type>& recv_sizes,
const std::vector<comm_index_type>& recv_offsets,
const std::vector<comm_index_type>& send_sizes,
const std::vector<comm_index_type>& send_offsets);

/**
* @copydoc collective_communicator::create_with_same_type
*/
Expand Down Expand Up @@ -141,10 +123,10 @@ class DenseCommunicator final : public CollectiveCommunicator {
private:
communicator comm_;

std::vector<distributed::comm_index_type> send_sizes_;
std::vector<distributed::comm_index_type> send_offsets_;
std::vector<distributed::comm_index_type> recv_sizes_;
std::vector<distributed::comm_index_type> recv_offsets_;
std::vector<comm_index_type> send_sizes_;
std::vector<comm_index_type> send_offsets_;
std::vector<comm_index_type> recv_sizes_;
std::vector<comm_index_type> recv_offsets_;
};


Expand Down
20 changes: 0 additions & 20 deletions include/ginkgo/core/distributed/neighborhood_communicator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,6 @@ class NeighborhoodCommunicator final : public CollectiveCommunicator {
communicator base,
const distributed::index_map<LocalIndexType, GlobalIndexType>& 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<comm_index_type>& sources,
const std::vector<comm_index_type>& recv_sizes,
const std::vector<comm_index_type>& recv_offsets,
const std::vector<comm_index_type>& destinations,
const std::vector<comm_index_type>& send_sizes,
const std::vector<comm_index_type>& send_offsets);

/**
* @copydoc collective_communicator::create_with_same_type
*/
Expand Down

0 comments on commit e7d32a1

Please sign in to comment.