AnasaziThyraDebugAdapter.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                 Anasazi: Block Eigensolvers Package
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 
00033 #ifndef ANASAZI_THYRA_DEBUG_ADAPTER_HPP
00034 #define ANASAZI_THYRA_DEBUG_ADAPTER_HPP
00035 
00036 #include "AnasaziConfigDefs.hpp"
00037 #include "AnasaziTypes.hpp"
00038 #include "AnasaziMultiVec.hpp"
00039 #include "AnasaziOperator.hpp"
00040 
00041 #include "AnasaziThyraAdapter.hpp"
00042 #include <Thyra_DetachedMultiVectorView.hpp>
00043 #include <Thyra_MultiVectorBase.hpp>
00044 #include <Thyra_MultiVectorStdOps.hpp>
00045 
00046 #include "Teuchos_TestForException.hpp"
00047 #include "Teuchos_SerialDenseMatrix.hpp"
00048 #include "Teuchos_RefCountPtr.hpp"
00049 #include "Teuchos_TimeMonitor.hpp"
00050 
00051 namespace Anasazi {
00052 
00054   
00056   //
00057   //--------template class AnasaziThyraMultiVec-----------------
00058   //
00060   
00068   template<class ScalarType>
00069   class ThyraMultiVec : public MultiVec<ScalarType> {
00070   public:
00071   
00072     typedef MultiVecTraits<ScalarType,Thyra::MultiVectorBase<ScalarType> > MVT;
00073     typedef Teuchos::ScalarTraits<ScalarType> SCT;
00074     typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
00075     typedef Teuchos::ScalarTraits<MagnitudeType> MT;
00076 
00078 
00079 
00081 
00085     ThyraMultiVec( const Teuchos::RCP<Thyra::MultiVectorBase< ScalarType > > & mv ) :
00086       _timerCreate(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::create")),
00087       _timerClone(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::clone")),
00088       _timerDestroy(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::destroy")),
00089       _timerMvTimesMatAddMv(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvtimesmataddmv")),
00090       _timerMvTransMv(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvtransmv")),
00091       _timerMvAddMv(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvaddmv")),
00092       _timerMvDot(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvdot")),
00093       _timerMvNorm(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvnorm")),
00094       _timerMvScale(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvscale")),
00095       _timerSetBlock(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::setblock")),
00096       _timerMvInit(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvinit")),
00097       _timerMvRandom(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvrandom"))
00098     {
00099       Teuchos::TimeMonitor timer(*_timerCreate);
00100       Thyra_MV = mv;
00101     }
00102 
00104 
00109     ThyraMultiVec( const Teuchos::RCP<Thyra::MultiVectorBase< ScalarType > > & mv, std::vector<Teuchos::RCP<Teuchos::Time> >& timers ) 
00110     {
00111       copyTimers( timers );
00112       Teuchos::TimeMonitor timer(*_timerCreate);
00113       Thyra_MV = mv;
00114     }
00115 
00117 
00121     ThyraMultiVec( const ThyraMultiVec<ScalarType> & mv ) 
00122     { 
00123       copyTimers( mv.getTimers() );
00124       Teuchos::TimeMonitor timer(*_timerCreate);
00125       Thyra_MV = MVT::CloneCopy( *(mv.getRCP()) );      
00126     }
00127     
00129     virtual ~ThyraMultiVec() { Teuchos::TimeMonitor timer(*_timerDestroy); }
00130 
00132 
00134 
00135 
00140     MultiVec<ScalarType> * Clone ( const int numvecs ) const 
00141     { 
00142       Teuchos::TimeMonitor timer(*_timerClone); 
00143       std::vector<Teuchos::RCP<Teuchos::Time> >  myTimers = getTimers();
00144       return new ThyraMultiVec<ScalarType>( MVT::Clone( *Thyra_MV, numvecs ), myTimers ); }
00145 
00151     MultiVec<ScalarType> * CloneCopy () const 
00152     { 
00153       Teuchos::TimeMonitor timer(*_timerClone);
00154       std::vector<Teuchos::RCP<Teuchos::Time> >  myTimers = getTimers();
00155       return new ThyraMultiVec<ScalarType>( MVT::CloneCopy( *Thyra_MV ), myTimers ); 
00156     }
00157 
00165     MultiVec<ScalarType> * CloneCopy ( const std::vector<int>& index ) const 
00166     { 
00167       Teuchos::TimeMonitor timer(*_timerClone);
00168       std::vector<Teuchos::RCP<Teuchos::Time> >  myTimers = getTimers();
00169       return new ThyraMultiVec<ScalarType>( MVT::CloneCopy( *Thyra_MV, index ), myTimers ); 
00170     }
00171     
00179     MultiVec<ScalarType> * CloneView ( const std::vector<int>& index ) 
00180     {
00181       Teuchos::TimeMonitor timer(*_timerClone); 
00182       std::vector<Teuchos::RCP<Teuchos::Time> >  myTimers = getTimers();
00183       return new ThyraMultiVec<ScalarType>( MVT::CloneView( *Thyra_MV, index ), myTimers ); 
00184     }
00185 
00187 
00189 
00190 
00192     int GetNumberVecs () const { return MVT::GetNumberVecs( *Thyra_MV ); }
00193 
00195     int GetVecLength () const { return MVT::GetVecLength( *Thyra_MV ); }
00196 
00198 
00200 
00201 
00203     void MvTimesMatAddMv ( ScalarType alpha, const MultiVec<ScalarType>& A, 
00204                            const Teuchos::SerialDenseMatrix<int,ScalarType>& B, 
00205                            ScalarType beta )
00206     { 
00207       Teuchos::TimeMonitor timer(*_timerMvTimesMatAddMv);
00208       const Anasazi::ThyraMultiVec<ScalarType>* vec_A = dynamic_cast<const Anasazi::ThyraMultiVec<ScalarType>* >(&A);
00209       MVT::MvTimesMatAddMv( alpha, *(vec_A->getRCP()), B, beta, *Thyra_MV ); 
00210     }
00211 
00214     void MvAddMv ( ScalarType alpha, const MultiVec<ScalarType>& A, 
00215                    ScalarType beta, const MultiVec<ScalarType>& B)
00216     { 
00217       Teuchos::TimeMonitor timer(*_timerMvAddMv);
00218       const Anasazi::ThyraMultiVec<ScalarType>* vec_A = dynamic_cast<const Anasazi::ThyraMultiVec<ScalarType>* >(&A);
00219       const Anasazi::ThyraMultiVec<ScalarType>* vec_B = dynamic_cast<const Anasazi::ThyraMultiVec<ScalarType>* >(&B);
00220       MVT::MvAddMv( alpha, *(vec_A->getRCP()), beta, *(vec_B->getRCP()), *Thyra_MV ); 
00221     }
00222 
00225     void MvTransMv ( ScalarType alpha, const MultiVec<ScalarType>& A, Teuchos::SerialDenseMatrix<int,ScalarType>& B 
00226 #ifdef HAVE_ANASAZI_EXPERIMENTAL
00227         , ConjType conj = Anasazi::CONJ
00228 #endif
00229         ) const
00230     { 
00231       Teuchos::TimeMonitor timer(*_timerMvTransMv);
00232       const Anasazi::ThyraMultiVec<ScalarType>* vec_A = dynamic_cast<const Anasazi::ThyraMultiVec<ScalarType>* >(&A);
00233       MVT::MvTransMv( alpha, *(vec_A->getRCP()), *Thyra_MV, B ); 
00234     }
00235   
00238     void MvDot ( const MultiVec<ScalarType>& A, std::vector<ScalarType> &b
00239 #ifdef HAVE_ANASAZI_EXPERIMENTAL
00240         , ConjType conj = Anasazi::CONJ
00241 #endif
00242         ) const
00243     { 
00244       Teuchos::TimeMonitor timer(*_timerMvDot);
00245       const Anasazi::ThyraMultiVec<ScalarType>* vec_A = dynamic_cast<const Anasazi::ThyraMultiVec<ScalarType>* >(&A);
00246       MVT::MvDot( *Thyra_MV, *(vec_A->getRCP()), b ); 
00247     }
00248 
00251     void MvScale ( ScalarType alpha ) { Teuchos::TimeMonitor timer(*_timerMvScale); MVT::MvScale( *Thyra_MV, alpha ); }
00252 
00255     void MvScale ( const std::vector<ScalarType>& alpha ) { Teuchos::TimeMonitor timer(*_timerMvScale); MVT::MvScale( *Thyra_MV, alpha ); }
00256 
00258 
00259 
00260     
00264     void MvNorm ( std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> &normvec ) const { Teuchos::TimeMonitor timer(*_timerMvNorm); MVT::MvNorm( *Thyra_MV, normvec ); }
00266     
00268 
00269 
00274     void SetBlock ( const MultiVec<ScalarType>& A, const std::vector<int>& index )
00275     {
00276       Teuchos::TimeMonitor timer(*_timerSetBlock);
00277       const Anasazi::ThyraMultiVec<ScalarType>* vec_A = dynamic_cast<const Anasazi::ThyraMultiVec<ScalarType>* >(&A);
00278       MVT::SetBlock( *(vec_A->getRCP()), index, *Thyra_MV );
00279     }
00280 
00283     void MvRandom() { Teuchos::TimeMonitor timer(*_timerMvRandom); MVT::MvRandom( *Thyra_MV ); }
00284 
00287     void MvInit ( ScalarType alpha ) { Teuchos::TimeMonitor timer(*_timerMvInit);  MVT::MvInit( *Thyra_MV, alpha ); }
00288 
00290 
00291 
00293     Teuchos::RCP< Thyra::MultiVectorBase<ScalarType> > getRCP() { return Thyra_MV; }
00294 
00297     Teuchos::RCP< const Thyra::MultiVectorBase<ScalarType> > getRCP() const { return Thyra_MV; }
00298 
00301     std::vector<Teuchos::RCP<Teuchos::Time> > getTimers() const {
00302      std::vector<Teuchos::RCP<Teuchos::Time> > timers;
00303      timers.push_back( _timerCreate ); 
00304      timers.push_back( _timerClone ); 
00305      timers.push_back( _timerDestroy ); 
00306      timers.push_back( _timerMvTimesMatAddMv ); 
00307      timers.push_back( _timerMvTransMv ); 
00308      timers.push_back( _timerMvAddMv ); 
00309      timers.push_back( _timerMvDot ); 
00310      timers.push_back( _timerMvNorm ); 
00311      timers.push_back( _timerMvScale ); 
00312      timers.push_back( _timerSetBlock ); 
00313      timers.push_back( _timerMvInit ); 
00314      timers.push_back( _timerMvRandom ); 
00315  
00316      return timers;
00317    }
00318 
00321    void copyTimers( std::vector<Teuchos::RCP<Teuchos::Time> >& timers ) {
00322      _timerCreate = timers[0];
00323      _timerClone = timers[1];
00324      _timerDestroy = timers[2];
00325      _timerMvTimesMatAddMv = timers[3];
00326      _timerMvTransMv = timers[4];
00327      _timerMvAddMv = timers[5];
00328      _timerMvDot = timers[6];
00329      _timerMvNorm = timers[7];
00330      _timerMvScale = timers[8];
00331      _timerSetBlock = timers[9];
00332      _timerMvInit = timers[10];
00333      _timerMvRandom = timers[11];
00334    } 
00336 
00338 
00339 
00340 
00342     void MvPrint( std::ostream& os ) const { MVT::MvPrint( *Thyra_MV, os ); }
00344 
00345   private:
00346 
00347     Teuchos::RCP<Thyra::MultiVectorBase<ScalarType> > Thyra_MV;
00348     Teuchos::RCP<Teuchos::Time> _timerCreate, _timerClone, _timerDestroy;
00349     Teuchos::RCP<Teuchos::Time> _timerMvTimesMatAddMv, _timerMvTransMv, _timerMvAddMv, _timerMvDot;
00350     Teuchos::RCP<Teuchos::Time> _timerMvNorm, _timerMvScale, _timerSetBlock, _timerMvInit, _timerMvRandom;
00351   };
00352   //-------------------------------------------------------------
00353   
00355   //
00356   //--------template class AnasaziThyraOp---------------------
00357   //
00359   
00366   template<class ScalarType>
00367   class ThyraOp : public virtual Operator<ScalarType> {
00368   public:
00369 
00370     typedef OperatorTraits<ScalarType,Thyra::MultiVectorBase<ScalarType>,Thyra::LinearOpBase<ScalarType> > OPT;
00371 
00373 
00374     
00376     ThyraOp(const Teuchos::RCP<const Thyra::LinearOpBase<ScalarType> > &Op ) { Thyra_Op = Op; }
00377     
00379     ~ThyraOp() {}
00381     
00383 
00384     
00388     void Apply ( const MultiVec<ScalarType>& X, MultiVec<ScalarType>& Y ) const 
00389     {
00390       const Anasazi::ThyraMultiVec<ScalarType>* vec_X = dynamic_cast<const Anasazi::ThyraMultiVec<ScalarType>* >(&X);
00391       Anasazi::ThyraMultiVec<ScalarType>* vec_Y = dynamic_cast<Anasazi::ThyraMultiVec<ScalarType>* >(&Y);
00392       OPT::Apply( *Thyra_Op, *(vec_X->getRCP()), *(vec_Y->getRCP()) );
00393     }
00394     
00396     
00397   private:
00398     Teuchos::RCP<const Thyra::LinearOpBase<ScalarType> > Thyra_Op;
00399   };
00400   
00401 } // end of Anasazi namespace 
00402 
00403 #endif 
00404 // end of file ANASAZI_THYRA_DEBUG_ADAPTER_HPP

Generated on Tue Jul 13 09:22:48 2010 for Anasazi by  doxygen 1.4.7