11 #include "Teuchos_Comm.hpp"
34 const Teuchos::Comm<int>& comm2) {
37 using Teuchos::MpiComm;
39 using Teuchos::rcp_dynamic_cast;
40 using Teuchos::rcpFromRef;
42 RCP<const MpiComm<int> > mpiComm1 =
43 rcp_dynamic_cast<
const MpiComm<int> >(rcpFromRef(comm1));
44 RCP<const MpiComm<int> > mpiComm2 =
45 rcp_dynamic_cast<
const MpiComm<int> >(rcpFromRef(comm2));
47 if (mpiComm1.is_null()) {
48 return comm1.getSize() == comm2.getSize();
50 if (mpiComm2.is_null()) {
51 return comm1.getSize() == comm2.getSize();
53 MPI_Comm rawMpiComm1 = *(mpiComm1->getRawMpiComm());
54 MPI_Comm rawMpiComm2 = *(mpiComm2->getRawMpiComm());
56 int result = MPI_UNEQUAL;
57 const int err = MPI_Comm_compare(rawMpiComm1, rawMpiComm2, &result);
58 TEUCHOS_TEST_FOR_EXCEPTION(err != MPI_SUCCESS, std::runtime_error,
59 "congruent: MPI_Comm_compare failed");
60 return result == MPI_IDENT || result == MPI_CONGRUENT;
64 return comm1.getSize() == comm2.getSize();
68 std::unique_ptr<std::string>
70 const char prefix[]) {
71 std::ostringstream os;
72 os <<
"Proc " << myRank <<
": " << prefix <<
": ";
73 return std::unique_ptr<std::string>(
new std::string(os.str()));
76 std::unique_ptr<std::string>
78 const char functionName[]) {
79 const int myRank = comm ==
nullptr ? -1 : comm->getRank();
80 const std::string prefix = std::string(
"Tpetra::") + functionName;
84 std::unique_ptr<std::string>
86 const char className[],
87 const char methodName[]) {
88 const int myRank = comm ==
nullptr ? -1 : comm->getRank();
89 const std::string prefix = std::string(
"Tpetra::") +
90 className + std::string(
"::") + methodName;
bool congruent(const Teuchos::Comm< int > &comm1, const Teuchos::Comm< int > &comm2)
Whether the two communicators are congruent.
Stand-alone utility functions and macros.
std::unique_ptr< std::string > createPrefix(const int myRank, const char prefix[])
Create string prefix for each line of verbose output.