diff --git a/include/ginkgo/core/base/mpi.hpp b/include/ginkgo/core/base/mpi.hpp index 862f145ae16..b9221c59745 100644 --- a/include/ginkgo/core/base/mpi.hpp +++ b/include/ginkgo/core/base/mpi.hpp @@ -513,10 +513,7 @@ class communicator { * * @return if the two comm objects are equal */ - bool operator==(const communicator& rhs) const - { - return compare(rhs.get()); - } + bool operator==(const communicator& rhs) const { return is_identical(rhs); } /** * Compare two communicator objects for non-equality. @@ -525,6 +522,39 @@ class communicator { */ bool operator!=(const communicator& rhs) const { return !(*this == rhs); } + /** + * Checks if the rhs communicator is identical to this communicator. + * + * @return true if rhs is identical to this + */ + bool is_identical(const communicator& rhs) const + { + if (!get() || !rhs.get()) { + return get() == rhs.get(); + } + int flag; + GKO_ASSERT_NO_MPI_ERRORS(MPI_Comm_compare(get(), rhs.get(), &flag)); + return flag == MPI_IDENT; + } + + /** + * Checks if the rhs communicator is congruent to this communicator. + * + * Congruent communicators are defined as having identical rank members and + * rank ordering. + * + * @return true if rhs is congruent to this + */ + bool is_congruent(const communicator& rhs) const + { + if (!get() || !rhs.get()) { + return get() == rhs.get(); + } + int flag; + GKO_ASSERT_NO_MPI_ERRORS(MPI_Comm_compare(get(), rhs.get(), &flag)); + return flag == MPI_CONGRUENT; + } + /** * This function is used to synchronize the ranks in the communicator. * Calls MPI_Barrier @@ -1492,13 +1522,6 @@ class communicator { GKO_ASSERT_NO_MPI_ERRORS(MPI_Comm_size(this->get(), &size)); return size; } - - bool compare(const MPI_Comm& other) const - { - int flag; - GKO_ASSERT_NO_MPI_ERRORS(MPI_Comm_compare(get(), other, &flag)); - return flag == MPI_IDENT; - } };