11 #include "Teuchos_Comm.hpp"
35 const Teuchos::Comm<int>& comm2)
40 using Teuchos::rcpFromRef;
41 using Teuchos::MpiComm;
42 using Teuchos::rcp_dynamic_cast;
44 RCP<const MpiComm<int> > mpiComm1 =
45 rcp_dynamic_cast<
const MpiComm<int> > (rcpFromRef (comm1));
46 RCP<const MpiComm<int> > mpiComm2 =
47 rcp_dynamic_cast<
const MpiComm<int> > (rcpFromRef (comm2));
49 if (mpiComm1.is_null ()) {
50 return comm1.getSize () == comm2.getSize ();
52 if (mpiComm2.is_null ()) {
53 return comm1.getSize () == comm2.getSize ();
55 MPI_Comm rawMpiComm1 = * (mpiComm1->getRawMpiComm ());
56 MPI_Comm rawMpiComm2 = * (mpiComm2->getRawMpiComm ());
58 int result = MPI_UNEQUAL;
59 const int err = MPI_Comm_compare (rawMpiComm1, rawMpiComm2, &result);
60 TEUCHOS_TEST_FOR_EXCEPTION(err != MPI_SUCCESS, std::runtime_error,
61 "congruent: MPI_Comm_compare failed");
62 return result == MPI_IDENT || result == MPI_CONGRUENT;
66 return comm1.getSize () == comm2.getSize ();
70 std::unique_ptr<std::string>
74 std::ostringstream os;
75 os <<
"Proc " << myRank <<
": " << prefix <<
": ";
76 return std::unique_ptr<std::string>(
new std::string(os.str()));
79 std::unique_ptr<std::string>
81 const char functionName[])
83 const int myRank = comm ==
nullptr ? -1 : comm->getRank();
84 const std::string prefix = std::string(
"Tpetra::") + functionName;
88 std::unique_ptr<std::string>
90 const char className[],
91 const char methodName[])
93 const int myRank = comm ==
nullptr ? -1 : comm->getRank();
94 const std::string prefix = std::string(
"Tpetra::") +
95 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.