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 00037 namespace Thyra { 00038 00039 00040 template<class Scalar> 00041 SpmdVectorSpaceDefaultBase<Scalar>::SpmdVectorSpaceDefaultBase() 00042 :mapCode_(-1), defaultLocalOffset_(-1), defaultGlobalDim_(-1), localSubDim_(-1) 00043 {} 00044 00045 00046 // Virtual methods with default implementations 00047 00048 00049 template<class Scalar> 00050 Index SpmdVectorSpaceDefaultBase<Scalar>::localOffset() const 00051 { 00052 return defaultLocalOffset_; 00053 } 00054 00055 00056 template<class Scalar> 00057 Index SpmdVectorSpaceDefaultBase<Scalar>::mapCode() const 00058 { 00059 return mapCode_; 00060 } 00061 00062 00063 template<class Scalar> 00064 std::string SpmdVectorSpaceDefaultBase<Scalar>::description() const 00065 { 00066 using Teuchos::RCP; using Teuchos::Comm; using Teuchos::null; 00067 std::ostringstream ostr; 00068 ostr << Teuchos::typeName(*this) << "{"; 00069 ostr << "globalDim="<<this->dim(); 00070 ostr << ",localSubDim="<<this->localSubDim(); 00071 ostr << ",localOffset="<<this->localOffset(); 00072 ostr << ",comm="; 00073 RCP<const Comm<Index> > comm; 00074 if ( (comm=this->getComm())!=null ) { 00075 ostr << comm->description(); 00076 } 00077 else { 00078 ostr << "NULL"; 00079 } 00080 ostr << "}"; 00081 return ostr.str(); 00082 } 00083 00084 00085 // Overridden from VectorSpaceBase 00086 00087 00088 template<class Scalar> 00089 Index SpmdVectorSpaceDefaultBase<Scalar>::dim() const 00090 { 00091 return defaultGlobalDim_; 00092 } 00093 00094 00095 template<class Scalar> 00096 Teuchos::RCP< const VectorSpaceFactoryBase<Scalar> > 00097 SpmdVectorSpaceDefaultBase<Scalar>::smallVecSpcFcty() const 00098 { 00099 return smallVecSpcFcty_; 00100 } 00101 00102 00103 template<class Scalar> 00104 bool SpmdVectorSpaceDefaultBase<Scalar>::isCompatible( 00105 const VectorSpaceBase<Scalar>& vecSpc 00106 ) const 00107 { 00108 00109 using Teuchos::ptrFromRef; 00110 using Teuchos::ptr_dynamic_cast; 00111 00112 // Check for exact match of vector space 00113 const Ptr<const SpmdVectorSpaceBase<Scalar> > 00114 spmdVecSpc = ptr_dynamic_cast<const SpmdVectorSpaceBase<Scalar> >(ptrFromRef(vecSpc)); 00115 if (nonnull(spmdVecSpc)) { 00116 return mapCode() == spmdVecSpc->mapCode(); 00117 } 00118 00119 // Check for in-core views 00120 if( this->hasInCoreView() && vecSpc.hasInCoreView() && this->dim() == vecSpc.dim() ) 00121 return true; 00122 // 2009/05/11: rabartl: ToDo: Remove this! 00123 00124 // Check for product vector interface 00125 const Ptr<const ProductVectorSpaceBase<Scalar> > pvsb = 00126 ptr_dynamic_cast<const ProductVectorSpaceBase<Scalar> >(ptrFromRef(vecSpc)); 00127 00128 if (nonnull(pvsb)) { 00129 if (pvsb->numBlocks() == 1 ) { 00130 return pvsb->getBlock(0)->isCompatible(*this); 00131 } 00132 else { 00133 return false; 00134 } 00135 } 00136 00137 // If we get here, we are not compatible! 00138 return false; 00139 00140 } 00141 00142 00143 // protected 00144 00145 00146 template<class Scalar> 00147 void SpmdVectorSpaceDefaultBase<Scalar>::updateState( const Index globalDim ) 00148 { 00149 localSubDim_ = this->localSubDim(); 00150 const Teuchos::RCP<const Teuchos::Comm<Index> > 00151 comm = this->getComm(); 00152 if( localSubDim_ >= 0 ) { 00153 int numProc = 1; 00154 int procRank = 0; 00155 if( comm.get() ) { 00156 numProc = comm->getSize(); 00157 procRank = comm->getRank(); 00158 } 00159 if( numProc > 1 && (localSubDim_ < globalDim || globalDim < 0) ) { 00160 mapCode_ = SpmdVectorSpaceUtilities::computeMapCode(*comm,localSubDim_); 00161 defaultLocalOffset_ 00162 = SpmdVectorSpaceUtilities::computeLocalOffset(*comm,localSubDim_); 00163 if( globalDim < 1 ) { 00164 defaultGlobalDim_ 00165 = SpmdVectorSpaceUtilities::computeGlobalDim(*comm,localSubDim_); 00166 } 00167 else { 00168 defaultGlobalDim_ = globalDim; 00169 // ToDo: Perform global reduction to check that this is correct in 00170 // debug build 00171 } 00172 } 00173 else { 00174 // This is a serial or a locally-replicated parallel 00175 // vector space. 00176 mapCode_ = localSubDim_; 00177 defaultLocalOffset_ = 0; 00178 defaultGlobalDim_ = localSubDim_; 00179 } 00180 } 00181 else { 00182 mapCode_ = -1; // Uninitialized! 00183 defaultLocalOffset_ = -1; 00184 defaultGlobalDim_ = -1; 00185 } 00186 smallVecSpcFcty_ 00187 = Teuchos::rcp(new DefaultSpmdVectorSpaceFactory<Scalar>(comm)); 00188 } 00189 00190 00191 } // end namespace Thyra 00192 00193 00194 #endif // THYRA_SPMD_VECTOR_SPACE_BASE_DEF_HPP
1.4.7