Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_Util.cpp
1// @HEADER
2// *****************************************************************************
3// Tpetra: Templated Linear Algebra Services Package
4//
5// Copyright 2008 NTESS and the Tpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#include "Tpetra_Util.hpp"
11#include "Teuchos_Comm.hpp"
12
13namespace Tpetra {
14namespace Details {
15
33bool congruent(const Teuchos::Comm<int>& comm1,
34 const Teuchos::Comm<int>& comm2) {
35#ifdef HAVE_MPI
36 using Teuchos::Comm;
37 using Teuchos::MpiComm;
38 using Teuchos::RCP;
39 using Teuchos::rcp_dynamic_cast;
40 using Teuchos::rcpFromRef;
41
46
47 if (mpiComm1.is_null()) { // comm1 is not an MpiComm
48 return comm1.getSize() == comm2.getSize(); // hope for the best
49 } else { // comm1 is an MpiComm
50 if (mpiComm2.is_null()) { // comm2 is not an MpiComm
51 return comm1.getSize() == comm2.getSize(); // hope for the best
52 } else { // both comm1 and comm2 are MpiComm
53 MPI_Comm rawMpiComm1 = *(mpiComm1->getRawMpiComm());
54 MPI_Comm rawMpiComm2 = *(mpiComm2->getRawMpiComm());
55
56 int result = MPI_UNEQUAL;
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;
61 }
62 }
63#else // NOT HAVE_MPI
64 return comm1.getSize() == comm2.getSize(); // hope for the best
65#endif // HAVE_MPI
66}
67
68std::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()));
74}
75
76std::unique_ptr<std::string>
77createPrefix(const Teuchos::Comm<int>* comm,
78 const char functionName[]) {
79 const int myRank = comm == nullptr ? -1 : comm->getRank();
80 const std::string prefix = std::string("Tpetra::") + functionName;
81 return createPrefix(myRank, prefix.c_str());
82}
83
84std::unique_ptr<std::string>
85createPrefix(const Teuchos::Comm<int>* comm,
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;
91 return createPrefix(myRank, prefix.c_str());
92}
93
94} // namespace Details
95} // namespace Tpetra
Stand-alone utility functions and macros.
Struct that holds views of the contents of a CrsMatrix.
Implementation details of Tpetra.
std::unique_ptr< std::string > createPrefix(const int myRank, const char prefix[])
Create string prefix for each line of verbose output.
bool congruent(const Teuchos::Comm< int > &comm1, const Teuchos::Comm< int > &comm2)
Whether the two communicators are congruent.
Namespace Tpetra contains the class and methods constituting the Tpetra library.