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 using ::Teuchos::MpiComm;
25 using ::Teuchos::SerialComm;
26
27 const MpiComm<int>* mpiComm = dynamic_cast<const MpiComm<int>*>(&comm);
28 if (mpiComm != NULL) { // It's an MpiComm; extract the MPI_Comm
29 MPI_Comm rawComm = *(mpiComm->getRawMpiComm());
30 return rawComm;
31 } else {
32 const SerialComm<int>* serialComm =
33 dynamic_cast<const SerialComm<int>*>(&comm);
34 if (serialComm != NULL) {
35 return MPI_COMM_SELF; // single-process comm including this process
36 } else {
37 throw std::invalid_argument(
38 "Tpetra::Details::extractMpiCommFromTeuchos: "
39 "Input Teuchos::Comm is "
40 "neither a Teuchos::MpiComm, "
41 "nor a Teuchos::SerialComm. "
42 "As a result, I don't know "
43 "how to get the MPI_Comm out of it.");
44 }
45 }
46}
47#endif // HAVE_TPETRACORE_MPI
48
49#ifdef HAVE_TPETRACORE_MPI
50bool teuchosCommIsAnMpiComm(const Teuchos::Comm<int>& comm) {
51 const Teuchos::MpiComm<int>* mpiComm =
52 dynamic_cast<const Teuchos::MpiComm<int>*>(&comm);
53 return mpiComm != nullptr;
54}
55#else
56bool teuchosCommIsAnMpiComm(const Teuchos::Comm<int>&) {
57 return false;
58}
59#endif // HAVE_TPETRACORE_MPI
60
61} // namespace Details
62} // namespace Tpetra
Declaration of Tpetra::Details::extractMpiCommFromTeuchos.
Implementation details of Tpetra.
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.