Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Epetra_TsqrMessenger.cpp
Go to the documentation of this file.
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 
24 
25 #include "TpetraCore_config.h"
26 
27 #if defined(HAVE_TPETRA_EPETRA) && defined(HAVE_TPETRA_TSQR)
28 
29 #include <Epetra_TsqrMessenger.hpp>
30 #include <Epetra_ConfigDefs.h> // EPETRA_MPI
31 #include <Teuchos_ConfigDefs.hpp> // HAVE_TEUCHOS_MPI
32 
33 // Make sure that both Epetra and Teuchos agree on whether MPI exists.
34 #if defined(EPETRA_MPI) && ! defined(HAVE_TEUCHOS_MPI)
35 # error "The Epetra package defines EPETRA_MPI, but the Teuchos package does NOT define HAVE_TEUCHOS_MPI. This means that one package thinks MPI exists, but the other package doesn't. This may indicate that Trilinos was not configured correctly. We can't continue building Trilinos in this case."
36 #elif ! defined(EPETRA_MPI) && defined(HAVE_TEUCHOS_MPI)
37 # error "The Epetra package does not define EPETRA_MPI, but the Teuchos package DOES define HAVE_TEUCHOS_MPI. This means that one package thinks MPI exists, but the other package doesn't. This may indicate that Trilinos was not configured correctly. We can't continue building Trilinos in this case."
38 #endif
39 
40 // Include Epetra's MPI wrappers.
41 #ifdef EPETRA_MPI
42 # include <Epetra_MpiComm.h>
43 #endif // EPETRA_MPI
44 #include <Epetra_SerialComm.h>
45 
46 // Include Teuchos' MPI wrappers.
47 #ifdef HAVE_TEUCHOS_MPI
48 # include <Teuchos_DefaultMpiComm.hpp>
49 #endif // HAVE_TEUCHOS_MPI
50 #include <Teuchos_DefaultSerialComm.hpp>
51 
52 
53 namespace TSQR {
54  namespace Epetra {
55 
56  Teuchos::RCP<const Teuchos::Comm<int> >
57  extractTeuchosComm (const Teuchos::RCP<const Epetra_Comm>& epetraComm)
58  {
59  using Teuchos::RCP;
60  using Teuchos::rcp;
61  using Teuchos::rcp_dynamic_cast;
62  using Teuchos::rcp_implicit_cast;
63 
64 #ifdef EPETRA_MPI
65  RCP<const Epetra_MpiComm> epetraMpiComm =
66  rcp_dynamic_cast<const Epetra_MpiComm> (epetraComm, false);
67  if (! epetraMpiComm.is_null ()) {
68  // It's OK to extract and use the raw MPI_Comm object, since
69  // an Epetra_MpiComm doesn't own (is not responsible for
70  // calling MPI_Comm_free on) its underlying MPI_Comm object.
71  MPI_Comm rawMpiComm = epetraMpiComm->Comm ();
72  RCP<const Teuchos::MpiComm<int> > teuchosMpiComm =
73  rcp (new Teuchos::MpiComm<int> (rawMpiComm));
74  return rcp_implicit_cast<const Teuchos::Comm<int> > (teuchosMpiComm);
75  }
76 #endif // EPETRA_MPI
77 
78  RCP<const Epetra_SerialComm> epetraSerialComm =
79  rcp_dynamic_cast<const Epetra_SerialComm> (epetraComm, false);
80  if (! epetraSerialComm.is_null ()) {
81  RCP<const Teuchos::SerialComm<int> > teuchosSerialComm =
82  rcp (new Teuchos::SerialComm<int> ());
83  return rcp_implicit_cast<const Teuchos::Comm<int> > (teuchosSerialComm);
84  }
85 
86  TEUCHOS_TEST_FOR_EXCEPTION(
87  true, std::invalid_argument, "The input Epetra_Comm object is neither "
88  "an Epetra_MpiComm nor an Epetra_SerialComm. This means that we don't"
89  " know how to convert it into a Teuchos::Comm<int> instance. You are "
90  "probably seeing this error message as a result of trying to invoke "
91  "TSQR (the Tall Skinny QR factorization) on an Epetra_MultiVector, "
92  "probably as a block orthogonalization method in either Anasazi or "
93  "Belos. TSQR currently only works on an Epetra_MultiVector if the "
94  "latter's communicator is either an Epetra_MpiComm (wraps MPI) or an "
95  "Epetra_SerialComm (\"stub\" communicator for a single process without "
96  "MPI).");
97  }
98  } // namespace Epetra
99 } // namespace TSQR
100 
101 #endif // defined(HAVE_TPETRA_EPETRA) && defined(HAVE_TPETRA_TSQR)
102 
Function for wrapping Epetra_Comm in a communicator wrapper that TSQR can use.