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_HPP 00030 #define THYRA_SPMD_VECTOR_SPACE_BASE_HPP 00031 00032 #include "Thyra_SpmdVectorSpaceDefaultBaseDecl.hpp" 00033 #include "Thyra_ScalarProdVectorSpaceBase.hpp" 00034 #include "Thyra_DefaultSpmdVectorSpaceFactory.hpp" 00035 #include "Thyra_SpmdVectorSpaceUtilities.hpp" 00036 00037 namespace Thyra { 00038 00039 template<class Scalar> 00040 SpmdVectorSpaceDefaultBase<Scalar>::SpmdVectorSpaceDefaultBase() 00041 :mapCode_(-1),defaultLocalOffset_(-1),defaultGlobalDim_(-1),localSubDim_(-1) 00042 {} 00043 00044 // Virtual methods with default implementations 00045 00046 template<class Scalar> 00047 Index SpmdVectorSpaceDefaultBase<Scalar>::localOffset() const 00048 { 00049 return defaultLocalOffset_; 00050 } 00051 00052 template<class Scalar> 00053 Index SpmdVectorSpaceDefaultBase<Scalar>::mapCode() const 00054 { 00055 return mapCode_; 00056 } 00057 00058 // Overridden from VectorSpaceBase 00059 00060 template<class Scalar> 00061 Index SpmdVectorSpaceDefaultBase<Scalar>::dim() const 00062 { 00063 return defaultGlobalDim_; 00064 } 00065 00066 template<class Scalar> 00067 Teuchos::RefCountPtr< const VectorSpaceFactoryBase<Scalar> > 00068 SpmdVectorSpaceDefaultBase<Scalar>::smallVecSpcFcty() const 00069 { 00070 return smallVecSpcFcty_; 00071 } 00072 00073 template<class Scalar> 00074 bool SpmdVectorSpaceDefaultBase<Scalar>::isCompatible( 00075 const VectorSpaceBase<Scalar>& vecSpc 00076 ) const 00077 { 00078 if( this->hasInCoreView() && vecSpc.hasInCoreView() ) 00079 return this->dim() == vecSpc.dim(); 00080 const SpmdVectorSpaceBase<Scalar> 00081 *mpiVecSpc = dynamic_cast<const SpmdVectorSpaceBase<Scalar>*>(&vecSpc); 00082 if(mpiVecSpc) 00083 return mapCode() == mpiVecSpc->mapCode(); 00084 return false; 00085 } 00086 00087 // protected 00088 00089 template<class Scalar> 00090 void SpmdVectorSpaceDefaultBase<Scalar>::updateState( const Index globalDim ) 00091 { 00092 localSubDim_ = this->localSubDim(); 00093 const Teuchos::RefCountPtr<const Teuchos::Comm<Index> > 00094 comm = this->getComm(); 00095 if( localSubDim_ >= 0 ) { 00096 int numProc = 1; 00097 int procRank = 0; 00098 if( comm.get() ) { 00099 numProc = comm->getSize(); 00100 procRank = comm->getRank(); 00101 } 00102 if( numProc > 1 && (localSubDim_ < globalDim || globalDim < 0) ) { 00103 mapCode_ = SpmdVectorSpaceUtilities::computeMapCode(*comm,localSubDim_); 00104 defaultLocalOffset_ 00105 = SpmdVectorSpaceUtilities::computeLocalOffset(*comm,localSubDim_); 00106 if( globalDim < 1 ) { 00107 defaultGlobalDim_ 00108 = SpmdVectorSpaceUtilities::computeGlobalDim(*comm,localSubDim_); 00109 } 00110 else { 00111 defaultGlobalDim_ = globalDim; 00112 // ToDo: Perform global reduction to check that this is correct in 00113 // debug build 00114 } 00115 } 00116 else { 00117 // This is a serial or a locally-replicated parallel 00118 // vector space. 00119 mapCode_ = localSubDim_; 00120 defaultLocalOffset_ = 0; 00121 defaultGlobalDim_ = localSubDim_; 00122 } 00123 } 00124 else { 00125 mapCode_ = -1; // Uninitialized! 00126 defaultLocalOffset_ = -1; 00127 defaultGlobalDim_ = -1; 00128 } 00129 smallVecSpcFcty_ 00130 = Teuchos::rcp(new DefaultSpmdVectorSpaceFactory<Scalar>(comm)); 00131 } 00132 00133 } // end namespace Thyra 00134 00135 #endif // THYRA_SPMD_VECTOR_SPACE_BASE_HPP
1.3.9.1