|
Tpetra Matrix/Vector Services
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Tpetra: Templated Linear Algebra Services Package 00005 // Copyright (2008) Sandia Corporation 00006 // 00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00008 // the U.S. Government retains certain rights in this software. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // ************************************************************************ 00040 // @HEADER 00041 00057 00058 #ifndef __Epetra_TsqrMessenger_hpp 00059 #define __Epetra_TsqrMessenger_hpp 00060 00061 #include <Tpetra_ConfigDefs.hpp> 00062 00063 #if defined(HAVE_TPETRA_EPETRA) && defined(HAVE_TPETRA_TSQR) 00064 00065 #include <Epetra_ConfigDefs.h> // EPETRA_MPI 00066 #include <Epetra_Comm.h> 00067 #ifdef EPETRA_MPI 00068 # include <Epetra_MpiComm.h> 00069 // #include <Epetra_MpiSmpComm.h> 00070 # include <Tsqr_MpiMessenger.hpp> 00071 #endif // EPETRA_MPI 00072 #include <Teuchos_RCP.hpp> 00073 #include <Tsqr_TrivialMessenger.hpp> 00074 00075 #include <algorithm> 00076 #include <utility> // std::pair 00077 00080 00081 namespace TSQR { 00082 namespace Epetra { 00083 00084 #ifdef EPETRA_MPI 00085 00086 00087 00088 00089 00090 00091 00092 static std::pair< MPI_Comm, bool > 00093 extractRawMpiComm (const Teuchos::RCP< const Epetra_Comm >& pComm) 00094 { 00095 using Teuchos::RCP; 00096 using Teuchos::rcp_dynamic_cast; 00097 00098 MPI_Comm rawMpiComm = MPI_COMM_NULL; 00099 bool haveMpiComm = false; 00100 00101 RCP< const Epetra_MpiComm > pMpiComm = 00102 rcp_dynamic_cast< const Epetra_MpiComm > (pComm, false); 00103 if (pMpiComm.get() == NULL) 00104 haveMpiComm = false; 00105 else 00106 { 00107 rawMpiComm = pMpiComm->Comm(); 00108 haveMpiComm = true; 00109 } 00110 return std::make_pair (rawMpiComm, haveMpiComm); 00111 } 00112 #endif // EPETRA_MPI 00113 00114 00119 template< class Datum > 00120 Teuchos::RCP< TSQR::MessengerBase< Datum > > 00121 makeTsqrMessenger (const Teuchos::RCP< const Epetra_Comm >& pComm) 00122 { 00123 using Teuchos::RCP; 00124 using Teuchos::rcp_implicit_cast; 00125 typedef TSQR::MessengerBase< Datum > base_mess_type; 00126 00127 #ifdef EPETRA_MPI 00128 // If the Epetra_Comm wraps MPI, then extract the raw MPI_Comm 00129 // object and use it to construct a TSQR messenger object that 00130 // wraps MPI. Otherwise, return a TSQR messenger object that 00131 // wraps trivial communication. 00132 std::pair< MPI_Comm, bool > results = extractRawMpiComm (pComm); 00133 if (results.second == true) 00134 { 00135 typedef TSQR::MPI::MpiMessenger< Datum > mess_type; 00136 00137 RCP< mess_type > pMess (new mess_type (results.first)); 00138 RCP< base_mess_type > pMessBase = 00139 rcp_implicit_cast< base_mess_type > (pMess); 00140 return pMessBase; 00141 } 00142 else 00143 #endif // EPETRA_MPI 00144 { 00145 typedef TSQR::TrivialMessenger< Datum > mess_type; 00146 00147 RCP< mess_type > pMess (new mess_type); 00148 RCP< base_mess_type > pMessBase = 00149 rcp_implicit_cast< base_mess_type > (pMess); 00150 return pMessBase; 00151 } 00152 } 00153 00154 } // namespace Epetra 00155 } // namespace TSQR 00156 00157 #endif // defined(HAVE_TPETRA_EPETRA) && defined(HAVE_TPETRA_TSQR) 00158 00159 #endif // __Epetra_TsqrMessenger_hpp 00160
1.7.6.1