Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Epetra_TsqrMessenger.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
56 
57 #include <Epetra_TsqrMessenger.hpp>
58 
59 #if defined(HAVE_TPETRA_EPETRA) && defined(HAVE_TPETRA_TSQR)
60 
61 #include <Epetra_ConfigDefs.h> // EPETRA_MPI
62 #include <Teuchos_ConfigDefs.hpp> // HAVE_TEUCHOS_MPI
63 
64 // Make sure that both Epetra and Teuchos agree on whether MPI exists.
65 #if defined(EPETRA_MPI) && ! defined(HAVE_TEUCHOS_MPI)
66 # 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."
67 #elif ! defined(EPETRA_MPI) && defined(HAVE_TEUCHOS_MPI)
68 # 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."
69 #endif
70 
71 // Include Epetra's MPI wrappers.
72 #ifdef EPETRA_MPI
73 # include <Epetra_MpiComm.h>
74 #endif // EPETRA_MPI
75 #include <Epetra_SerialComm.h>
76 
77 // Include Teuchos' MPI wrappers.
78 #ifdef HAVE_TEUCHOS_MPI
79 # include <Teuchos_DefaultMpiComm.hpp>
80 #endif // HAVE_TEUCHOS_MPI
81 #include <Teuchos_DefaultSerialComm.hpp>
82 
83 
84 namespace TSQR {
85  namespace Epetra {
86 
87  Teuchos::RCP<const Teuchos::Comm<int> >
88  extractTeuchosComm (const Teuchos::RCP<const Epetra_Comm>& epetraComm)
89  {
90  using Teuchos::RCP;
91  using Teuchos::rcp;
92  using Teuchos::rcp_dynamic_cast;
93  using Teuchos::rcp_implicit_cast;
94 
95 #ifdef EPETRA_MPI
96  RCP<const Epetra_MpiComm> epetraMpiComm =
97  rcp_dynamic_cast<const Epetra_MpiComm> (epetraComm, false);
98  if (! epetraMpiComm.is_null ()) {
99  // It's OK to extract and use the raw MPI_Comm object, since
100  // an Epetra_MpiComm doesn't own (is not responsible for
101  // calling MPI_Comm_free on) its underlying MPI_Comm object.
102  MPI_Comm rawMpiComm = epetraMpiComm->Comm ();
103  RCP<const Teuchos::MpiComm<int> > teuchosMpiComm =
104  rcp (new Teuchos::MpiComm<int> (rawMpiComm));
105  return rcp_implicit_cast<const Teuchos::Comm<int> > (teuchosMpiComm);
106  }
107 #endif // EPETRA_MPI
108 
109  RCP<const Epetra_SerialComm> epetraSerialComm =
110  rcp_dynamic_cast<const Epetra_SerialComm> (epetraComm, false);
111  if (! epetraSerialComm.is_null ()) {
112  RCP<const Teuchos::SerialComm<int> > teuchosSerialComm =
113  rcp (new Teuchos::SerialComm<int> ());
114  return rcp_implicit_cast<const Teuchos::Comm<int> > (teuchosSerialComm);
115  }
116 
117  TEUCHOS_TEST_FOR_EXCEPTION(
118  true, std::invalid_argument, "The input Epetra_Comm object is neither "
119  "an Epetra_MpiComm nor an Epetra_SerialComm. This means that we don't"
120  " know how to convert it into a Teuchos::Comm<int> instance. You are "
121  "probably seeing this error message as a result of trying to invoke "
122  "TSQR (the Tall Skinny QR factorization) on an Epetra_MultiVector, "
123  "probably as a block orthogonalization method in either Anasazi or "
124  "Belos. TSQR currently only works on an Epetra_MultiVector if the "
125  "latter's communicator is either an Epetra_MpiComm (wraps MPI) or an "
126  "Epetra_SerialComm (\"stub\" communicator for a single process without "
127  "MPI).");
128  }
129  } // namespace Epetra
130 } // namespace TSQR
131 
132 #endif // defined(HAVE_TPETRA_EPETRA) && defined(HAVE_TPETRA_TSQR)
133 
Function for wrapping Epetra_Comm in a communicator wrapper that TSQR can use.