Skip to content

Commit

Permalink
[coll-comm] review update:
Browse files Browse the repository at this point in the history
- fix include guards
- update docs
- implement copy/move constructors/assignment with tests
- add equality test for collective communicators (needed for testing)
- always enable neighborhood comm, just throw if openmpi is too old

Co-authored-by: Pratik Nayak <pratik.nayak@kit.edu>
  • Loading branch information
MarcelKoch and pratikvn committed Aug 16, 2024
1 parent b61ad41 commit 1f49b91
Show file tree
Hide file tree
Showing 11 changed files with 382 additions and 88 deletions.
6 changes: 1 addition & 5 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,10 @@ if(GINKGO_BUILD_MPI)
distributed/collective_communicator.cpp
distributed/dense_communicator.cpp
distributed/matrix.cpp
distributed/neighborhood_communicator.cpp
distributed/partition_helpers.cpp
distributed/vector.cpp
distributed/preconditioner/schwarz.cpp)
if(NOT GINKGO_HAVE_OPENMPI_PRE_4_1_X)
target_sources(${ginkgo_core}
PRIVATE
distributed/neighborhood_communicator.cpp)
endif()
endif()

# MSVC/shared: make ginkgo be the major library
Expand Down
43 changes: 43 additions & 0 deletions core/distributed/dense_communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ GKO_INSTANTIATE_FOR_EACH_LOCAL_GLOBAL_INDEX_TYPE(GKO_DECLARE_DENSE_CONSTRUCTOR);
#undef GKO_DECLARE_DENSE_CONSTRUCTOR


DenseCommunicator::DenseCommunicator(DenseCommunicator&& other) noexcept
: DenseCommunicator(other.get_base_communicator())
{
*this = std::move(other);
}


DenseCommunicator& DenseCommunicator::operator=(
DenseCommunicator&& other) noexcept
{
if (this != &other) {
*this = other;
std::fill(other.send_sizes_.begin(), other.send_sizes_.end(), 0);
std::fill(other.send_offsets_.begin(), other.send_offsets_.end(), 0);
std::fill(other.recv_sizes_.begin(), other.recv_sizes_.end(), 0);
std::fill(other.recv_offsets_.begin(), other.recv_offsets_.end(), 0);
}
return *this;
}


DenseCommunicator::DenseCommunicator(
communicator base, const std::vector<comm_index_type>& recv_sizes,
const std::vector<comm_index_type>& recv_offsets,
Expand Down Expand Up @@ -125,6 +146,28 @@ comm_index_type DenseCommunicator::get_send_size() const
}


bool operator==(const DenseCommunicator& a, const DenseCommunicator& b)
{
return (a.comm_.is_identical(b.comm_) || a.comm_.is_congruent(b.comm_)) &&
a.send_sizes_.size() == b.send_sizes_.size() &&
a.recv_sizes_.size() == b.recv_sizes_.size() &&
std::equal(a.send_sizes_.begin(), a.send_sizes_.end(),
b.send_sizes_.begin()) &&
std::equal(a.recv_sizes_.begin(), a.recv_sizes_.end(),
b.recv_sizes_.begin()) &&
std::equal(a.send_offsets_.begin(), a.send_offsets_.end(),
b.send_offsets_.begin()) &&
std::equal(a.recv_offsets_.begin(), a.recv_offsets_.end(),
b.recv_offsets_.begin());
}


bool operator!=(const DenseCommunicator& a, const DenseCommunicator& b)
{
return !(a == b);
}


} // namespace mpi
} // namespace experimental
} // namespace gko
6 changes: 3 additions & 3 deletions core/distributed/device_partition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ginkgo/core/distributed/partition.hpp>

Expand Down Expand Up @@ -89,4 +89,4 @@ to_device_const(
} // namespace gko


#endif // GINKGO_PARTITION_HPP
#endif // GKO_CORE_DISTRIBUTED_PARTITION_HPP
59 changes: 59 additions & 0 deletions core/distributed/neighborhood_communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,17 @@ request NeighborhoodCommunicator::i_all_to_all_v(
std::shared_ptr<const Executor> exec, const void* send_buffer,
MPI_Datatype send_type, void* recv_buffer, MPI_Datatype recv_type) const
{
#if GINKGO_HAVE_OPENMPI_PRE_4_1_X
GKO_NOT_IMPLEMENTED;
#else
auto guard = exec->get_scoped_device_id_guard();
request req;
GKO_ASSERT_NO_MPI_ERRORS(MPI_Ineighbor_alltoallv(
send_buffer, send_sizes_.data(), send_offsets_.data(), send_type,
recv_buffer, recv_sizes_.data(), recv_offsets_.data(), recv_type,
comm_.get(), req.get()));
return req;
#endif
}


Expand All @@ -179,6 +183,61 @@ NeighborhoodCommunicator::create_with_same_type(
}


NeighborhoodCommunicator::NeighborhoodCommunicator(
NeighborhoodCommunicator&& other) noexcept
: NeighborhoodCommunicator(other.get_base_communicator())
{
*this = std::move(other);
}


NeighborhoodCommunicator& NeighborhoodCommunicator::operator=(
NeighborhoodCommunicator&& other) noexcept
{
if (this != &other) {
comm_ = std::exchange(other.comm_, MPI_COMM_SELF);
// set topology for other comm
std::vector<comm_index_type> non_nullptr(1);
non_nullptr.resize(0);
other.comm_ = create_neighborhood_comm(this->get_base_communicator(),
non_nullptr, non_nullptr);
send_sizes_ = std::exchange(
other.send_sizes_, std::vector<distributed::comm_index_type>{});
send_offsets_ = std::exchange(
other.send_offsets_, std::vector<distributed::comm_index_type>{0});
recv_sizes_ = std::exchange(
other.recv_sizes_, std::vector<distributed::comm_index_type>{});
recv_offsets_ = std::exchange(
other.recv_offsets_, std::vector<distributed::comm_index_type>{0});
}
return *this;
}


bool operator==(const NeighborhoodCommunicator& a,
const NeighborhoodCommunicator& b)
{
return (a.comm_.is_identical(b.comm_) || a.comm_.is_congruent(b.comm_)) &&
a.send_sizes_.size() == b.send_sizes_.size() &&
a.recv_sizes_.size() == b.recv_sizes_.size() &&
std::equal(a.send_sizes_.begin(), a.send_sizes_.end(),
b.send_sizes_.begin()) &&
std::equal(a.recv_sizes_.begin(), a.recv_sizes_.end(),
b.recv_sizes_.begin()) &&
std::equal(a.send_offsets_.begin(), a.send_offsets_.end(),
b.send_offsets_.begin()) &&
std::equal(a.recv_offsets_.begin(), a.recv_offsets_.end(),
b.recv_offsets_.begin());
}


bool operator!=(const NeighborhoodCommunicator& a,
const NeighborhoodCommunicator& b)
{
return !(a == b);
}


template <typename LocalIndexType, typename GlobalIndexType>
NeighborhoodCommunicator::NeighborhoodCommunicator(
communicator base,
Expand Down
Loading

0 comments on commit 1f49b91

Please sign in to comment.