Skip to content

Commit

Permalink
[mpi] add explicit comparison for identical and congruent
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelKoch committed Aug 9, 2024
1 parent 0a8067b commit b61ad41
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions include/ginkgo/core/base/mpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
};


Expand Down

0 comments on commit b61ad41

Please sign in to comment.