Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_Details_extractMpiCommFromTeuchos.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
11
12#ifdef HAVE_TPETRACORE_MPI
13# include "Teuchos_DefaultMpiComm.hpp"
14# include "Teuchos_DefaultSerialComm.hpp"
15# include <stdexcept>
16#endif // HAVE_TPETRACORE_MPI
17
18namespace Tpetra {
19namespace Details {
20
21#ifdef HAVE_TPETRACORE_MPI
22MPI_Comm
23extractMpiCommFromTeuchos (const Teuchos::Comm<int>& comm)
24{
25 using ::Teuchos::MpiComm;
26 using ::Teuchos::SerialComm;
27
28 const MpiComm<int>* mpiComm = dynamic_cast<const MpiComm<int>* > (&comm);
29 if (mpiComm != NULL) { // It's an MpiComm; extract the MPI_Comm
30 MPI_Comm rawComm = * (mpiComm->getRawMpiComm ());
31 return rawComm;
32 }
33 else {
34 const SerialComm<int>* serialComm =
35 dynamic_cast<const SerialComm<int>* > (&comm);
36 if (serialComm != NULL) {
37 return MPI_COMM_SELF; // single-process comm including this process
38 }
39 else {
40 throw std::invalid_argument ("Tpetra::Details::extractMpiCommFromTeuchos: "
41 "Input Teuchos::Comm is "
42 "neither a Teuchos::MpiComm, "
43 "nor a Teuchos::SerialComm. "
44 "As a result, I don't know "
45 "how to get the MPI_Comm out of it.");
46 }
47 }
48}
49#endif // HAVE_TPETRACORE_MPI
50
51#ifdef HAVE_TPETRACORE_MPI
52bool teuchosCommIsAnMpiComm (const Teuchos::Comm<int>& comm)
53{
54 const Teuchos::MpiComm<int>* mpiComm =
55 dynamic_cast<const Teuchos::MpiComm<int>* > (&comm);
56 return mpiComm != nullptr;
57}
58#else
59bool teuchosCommIsAnMpiComm (const Teuchos::Comm<int>&)
60{
61 return false;
62}
63#endif // HAVE_TPETRACORE_MPI
64
65} // namespace Details
66} // namespace Tpetra
67
Declaration of Tpetra::Details::extractMpiCommFromTeuchos.
Nonmember function that computes a residual Computes R = B - A * X.
bool teuchosCommIsAnMpiComm(const Teuchos::Comm< int > &)
Is the given Comm a Teuchos::MpiComm<int> instance?
Namespace Tpetra contains the class and methods constituting the Tpetra library.