|
Thyra Package Browser (Single Doxygen Collection) Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Thyra: Interfaces and Support for Abstract Numerical Algorithms 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef THYRA_SPMD_VECTOR_SPACE_BASE_DEF_HPP 00030 #define THYRA_SPMD_VECTOR_SPACE_BASE_DEF_HPP 00031 00032 #include "Thyra_SpmdVectorSpaceDefaultBase_decl.hpp" 00033 #include "Thyra_ScalarProdVectorSpaceBase.hpp" 00034 #include "Thyra_DefaultSpmdVectorSpaceFactory.hpp" 00035 #include "Thyra_SpmdVectorSpaceUtilities.hpp" 00036 #include "Thyra_ProductVectorSpaceBase.hpp" 00037 00038 00039 namespace Thyra { 00040 00041 00042 template<class Scalar> 00043 SpmdVectorSpaceDefaultBase<Scalar>::SpmdVectorSpaceDefaultBase() 00044 :mapCode_(-1), defaultLocalOffset_(-1), defaultGlobalDim_(-1), localSubDim_(-1) 00045 {} 00046 00047 00048 // Virtual methods with default implementations 00049 00050 00051 template<class Scalar> 00052 Ordinal SpmdVectorSpaceDefaultBase<Scalar>::localOffset() const 00053 { 00054 return defaultLocalOffset_; 00055 } 00056 00057 00058 template<class Scalar> 00059 Ordinal SpmdVectorSpaceDefaultBase<Scalar>::mapCode() const 00060 { 00061 return mapCode_; 00062 } 00063 00064 00065 template<class Scalar> 00066 std::string SpmdVectorSpaceDefaultBase<Scalar>::description() const 00067 { 00068 using Teuchos::RCP; using Teuchos::Comm; using Teuchos::null; 00069 std::ostringstream ostr; 00070 ostr << Teuchos::typeName(*this) << "{"; 00071 ostr << "globalDim="<<this->dim(); 00072 ostr << ",localSubDim="<<this->localSubDim(); 00073 ostr << ",localOffset="<<this->localOffset(); 00074 ostr << ",comm="; 00075 RCP<const Comm<Ordinal> > comm; 00076 if ( (comm=this->getComm())!=null ) { 00077 ostr << comm->description(); 00078 } 00079 else { 00080 ostr << "NULL"; 00081 } 00082 ostr << "}"; 00083 return ostr.str(); 00084 } 00085 00086 00087 // Overridden from VectorSpaceBase 00088 00089 00090 template<class Scalar> 00091 Ordinal SpmdVectorSpaceDefaultBase<Scalar>::dim() const 00092 { 00093 return defaultGlobalDim_; 00094 } 00095 00096 00097 template<class Scalar> 00098 Teuchos::RCP< const VectorSpaceFactoryBase<Scalar> > 00099 SpmdVectorSpaceDefaultBase<Scalar>::smallVecSpcFcty() const 00100 { 00101 return smallVecSpcFcty_; 00102 } 00103 00104 00105 template<class Scalar> 00106 bool SpmdVectorSpaceDefaultBase<Scalar>::isCompatible( 00107 const VectorSpaceBase<Scalar>& vecSpc 00108 ) const 00109 { 00110 00111 using Teuchos::ptrFromRef; 00112 using Teuchos::ptr_dynamic_cast; 00113 00114 // Check for exact match of vector space 00115 const Ptr<const SpmdVectorSpaceBase<Scalar> > 00116 spmdVecSpc = ptr_dynamic_cast<const SpmdVectorSpaceBase<Scalar> >(ptrFromRef(vecSpc)); 00117 if (nonnull(spmdVecSpc)) { 00118 return mapCode() == spmdVecSpc->mapCode(); 00119 } 00120 00121 // Check for in-core views 00122 if( this->hasInCoreView() && vecSpc.hasInCoreView() && this->dim() == vecSpc.dim() ) 00123 return true; 00124 // 2009/05/11: rabartl: ToDo: Remove this! 00125 00126 // Check for product vector interface 00127 const Ptr<const ProductVectorSpaceBase<Scalar> > pvsb = 00128 ptr_dynamic_cast<const ProductVectorSpaceBase<Scalar> >(ptrFromRef(vecSpc)); 00129 00130 if (nonnull(pvsb)) { 00131 if (pvsb->numBlocks() == 1 ) { 00132 return pvsb->getBlock(0)->isCompatible(*this); 00133 } 00134 else { 00135 return false; 00136 } 00137 } 00138 00139 // If we get here, we are not compatible! 00140 return false; 00141 00142 } 00143 00144 00145 // protected 00146 00147 00148 template<class Scalar> 00149 void SpmdVectorSpaceDefaultBase<Scalar>::updateState( const Ordinal globalDim ) 00150 { 00151 localSubDim_ = this->localSubDim(); 00152 const Teuchos::RCP<const Teuchos::Comm<Ordinal> > 00153 comm = this->getComm(); 00154 if( localSubDim_ >= 0 ) { 00155 int numProc = 1; 00156 int procRank = 0; 00157 if( comm.get() ) { 00158 numProc = comm->getSize(); 00159 procRank = comm->getRank(); 00160 } 00161 if( numProc > 1 && (localSubDim_ < globalDim || globalDim < 0) ) { 00162 mapCode_ = SpmdVectorSpaceUtilities::computeMapCode(*comm,localSubDim_); 00163 defaultLocalOffset_ 00164 = SpmdVectorSpaceUtilities::computeLocalOffset(*comm,localSubDim_); 00165 if( globalDim < 1 ) { 00166 defaultGlobalDim_ 00167 = SpmdVectorSpaceUtilities::computeGlobalDim(*comm,localSubDim_); 00168 } 00169 else { 00170 defaultGlobalDim_ = globalDim; 00171 // ToDo: Perform global reduction to check that this is correct in 00172 // debug build 00173 } 00174 } 00175 else { 00176 // This is a serial or a locally-replicated parallel 00177 // vector space. 00178 mapCode_ = localSubDim_; 00179 defaultLocalOffset_ = 0; 00180 defaultGlobalDim_ = localSubDim_; 00181 } 00182 } 00183 else { 00184 mapCode_ = -1; // Uninitialized! 00185 defaultLocalOffset_ = -1; 00186 defaultGlobalDim_ = -1; 00187 } 00188 smallVecSpcFcty_ = defaultSpmdVectorSpaceFactory<Scalar>(comm); 00189 } 00190 00191 00192 } // end namespace Thyra 00193 00194 00195 #endif // THYRA_SPMD_VECTOR_SPACE_BASE_DEF_HPP
1.7.4