Anasazi Version of the Day
Loading...
Searching...
No Matches
AnasaziThyraDebugAdapter.hpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Anasazi: Block Eigensolvers Package
5// Copyright 2004 Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38//
39// ***********************************************************************
40// @HEADER
41
46#ifndef ANASAZI_THYRA_DEBUG_ADAPTER_HPP
47#define ANASAZI_THYRA_DEBUG_ADAPTER_HPP
48
49#include "AnasaziConfigDefs.hpp"
50#include "AnasaziTypes.hpp"
51#include "AnasaziMultiVec.hpp"
52#include "AnasaziOperator.hpp"
53
55#include <Thyra_DetachedMultiVectorView.hpp>
56#include <Thyra_MultiVectorBase.hpp>
57#include <Thyra_MultiVectorStdOps.hpp>
58
59#include "Teuchos_Assert.hpp"
60#include "Teuchos_SerialDenseMatrix.hpp"
61#include "Teuchos_RCP.hpp"
62#include "Teuchos_TimeMonitor.hpp"
63
64namespace Anasazi {
65
67
69 //
70 //--------template class AnasaziThyraMultiVec-----------------
71 //
73
81 template<class ScalarType>
82 class ThyraMultiVec : public MultiVec<ScalarType> {
83 public:
84
86 typedef Teuchos::ScalarTraits<ScalarType> SCT;
87 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
88 typedef Teuchos::ScalarTraits<MagnitudeType> MT;
89
91
92
94
98 ThyraMultiVec( const Teuchos::RCP<Thyra::MultiVectorBase< ScalarType > > & mv ) :
99 _timerCreate(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::create")),
100 _timerClone(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::clone")),
101 _timerDestroy(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::destroy")),
102 _timerMvTimesMatAddMv(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvtimesmataddmv")),
103 _timerMvTransMv(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvtransmv")),
104 _timerMvAddMv(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvaddmv")),
105 _timerMvDot(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvdot")),
106 _timerMvNorm(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvnorm")),
107 _timerMvScale(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvscale")),
108 _timerSetBlock(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::setblock")),
109 _timerMvInit(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvinit")),
110 _timerMvRandom(Teuchos::TimeMonitor::getNewTimer("ThyraMultiVec::mvrandom"))
111 {
112 Teuchos::TimeMonitor timer(*_timerCreate);
113 Thyra_MV = mv;
114 }
115
117
122 ThyraMultiVec( const Teuchos::RCP<Thyra::MultiVectorBase< ScalarType > > & mv, std::vector<Teuchos::RCP<Teuchos::Time> >& timers )
123 {
124 copyTimers( timers );
125 Teuchos::TimeMonitor timer(*_timerCreate);
126 Thyra_MV = mv;
127 }
128
130
135 {
136 copyTimers( mv.getTimers() );
137 Teuchos::TimeMonitor timer(*_timerCreate);
138 Thyra_MV = MVT::CloneCopy( *(mv.getRCP()) );
139 }
140
142 virtual ~ThyraMultiVec() { Teuchos::TimeMonitor timer(*_timerDestroy); }
143
145
147
148
153 MultiVec<ScalarType> * Clone ( const int numvecs ) const
154 {
155 Teuchos::TimeMonitor timer(*_timerClone);
156 std::vector<Teuchos::RCP<Teuchos::Time> > myTimers = getTimers();
157 return new ThyraMultiVec<ScalarType>( MVT::Clone( *Thyra_MV, numvecs ), myTimers ); }
158
165 {
166 Teuchos::TimeMonitor timer(*_timerClone);
167 std::vector<Teuchos::RCP<Teuchos::Time> > myTimers = getTimers();
168 return new ThyraMultiVec<ScalarType>( MVT::CloneCopy( *Thyra_MV ), myTimers );
169 }
170
178 MultiVec<ScalarType> * CloneCopy ( const std::vector<int>& index ) const
179 {
180 Teuchos::TimeMonitor timer(*_timerClone);
181 std::vector<Teuchos::RCP<Teuchos::Time> > myTimers = getTimers();
182 return new ThyraMultiVec<ScalarType>( MVT::CloneCopy( *Thyra_MV, index ), myTimers );
183 }
184
192 MultiVec<ScalarType> * CloneViewNonConst ( const std::vector<int>& index )
193 {
194 Teuchos::TimeMonitor timer(*_timerClone);
195 std::vector<Teuchos::RCP<Teuchos::Time> > myTimers = getTimers();
196 return new ThyraMultiVec<ScalarType>( MVT::CloneViewNonConst( *Thyra_MV, index ), myTimers );
197 }
198
206 const MultiVec<ScalarType> * CloneView ( const std::vector<int>& index ) const
207 {
208 Teuchos::TimeMonitor timer(*_timerClone);
209 std::vector<Teuchos::RCP<Teuchos::Time> > myTimers = getTimers();
210 Teuchos::RCP<Thyra::MultiVectorBase<ScalarType> > nonconst_ptr_to_const_view = Teuchos::rcp_const_cast<Thyra::MultiVectorBase<ScalarType> >( MVT::CloneView(*Thyra_MV,index) );
211 const MultiVec<ScalarType> * const_ret = new ThyraMultiVec<ScalarType>( nonconst_ptr_to_const_view, myTimers );
212 return const_ret;
213 }
214
216
218
219
221 int GetNumberVecs () const { return MVT::GetNumberVecs( *Thyra_MV ); }
222
224 ptrdiff_t GetGlobalLength () const { return MVT::GetGlobalLength( *Thyra_MV ); }
225
227
229
230
232 void MvTimesMatAddMv ( ScalarType alpha, const MultiVec<ScalarType>& A,
233 const Teuchos::SerialDenseMatrix<int,ScalarType>& B,
234 ScalarType beta )
235 {
236 Teuchos::TimeMonitor timer(*_timerMvTimesMatAddMv);
237 const Anasazi::ThyraMultiVec<ScalarType>* vec_A = dynamic_cast<const Anasazi::ThyraMultiVec<ScalarType>* >(&A);
238 MVT::MvTimesMatAddMv( alpha, *(vec_A->getRCP()), B, beta, *Thyra_MV );
239 }
240
243 void MvAddMv ( ScalarType alpha, const MultiVec<ScalarType>& A,
244 ScalarType beta, const MultiVec<ScalarType>& B)
245 {
246 Teuchos::TimeMonitor timer(*_timerMvAddMv);
247 const Anasazi::ThyraMultiVec<ScalarType>* vec_A = dynamic_cast<const Anasazi::ThyraMultiVec<ScalarType>* >(&A);
248 const Anasazi::ThyraMultiVec<ScalarType>* vec_B = dynamic_cast<const Anasazi::ThyraMultiVec<ScalarType>* >(&B);
249 MVT::MvAddMv( alpha, *(vec_A->getRCP()), beta, *(vec_B->getRCP()), *Thyra_MV );
250 }
251
254 void MvTransMv ( ScalarType alpha, const MultiVec<ScalarType>& A, Teuchos::SerialDenseMatrix<int,ScalarType>& B
255#ifdef HAVE_ANASAZI_EXPERIMENTAL
256 , ConjType conj = Anasazi::CONJ
257#endif
258 ) const
259 {
260 Teuchos::TimeMonitor timer(*_timerMvTransMv);
261 const Anasazi::ThyraMultiVec<ScalarType>* vec_A = dynamic_cast<const Anasazi::ThyraMultiVec<ScalarType>* >(&A);
262 MVT::MvTransMv( alpha, *(vec_A->getRCP()), *Thyra_MV, B );
263 }
264
267 void MvDot ( const MultiVec<ScalarType>& A, std::vector<ScalarType> &b
268#ifdef HAVE_ANASAZI_EXPERIMENTAL
269 , ConjType conj = Anasazi::CONJ
270#endif
271 ) const
272 {
273 Teuchos::TimeMonitor timer(*_timerMvDot);
274 const Anasazi::ThyraMultiVec<ScalarType>* vec_A = dynamic_cast<const Anasazi::ThyraMultiVec<ScalarType>* >(&A);
275 MVT::MvDot( *Thyra_MV, *(vec_A->getRCP()), b );
276 }
277
280 void MvScale ( ScalarType alpha ) { Teuchos::TimeMonitor timer(*_timerMvScale); MVT::MvScale( *Thyra_MV, alpha ); }
281
284 void MvScale ( const std::vector<ScalarType>& alpha ) { Teuchos::TimeMonitor timer(*_timerMvScale); MVT::MvScale( *Thyra_MV, alpha ); }
285
287
289
293 void MvNorm ( std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> &normvec ) const { Teuchos::TimeMonitor timer(*_timerMvNorm); MVT::MvNorm( *Thyra_MV, normvec ); }
295
297
298
303 void SetBlock ( const MultiVec<ScalarType>& A, const std::vector<int>& index )
304 {
305 Teuchos::TimeMonitor timer(*_timerSetBlock);
306 const Anasazi::ThyraMultiVec<ScalarType>* vec_A = dynamic_cast<const Anasazi::ThyraMultiVec<ScalarType>* >(&A);
307 MVT::SetBlock( *(vec_A->getRCP()), index, *Thyra_MV );
308 }
309
312 void MvRandom() { Teuchos::TimeMonitor timer(*_timerMvRandom); MVT::MvRandom( *Thyra_MV ); }
313
316 void MvInit ( ScalarType alpha ) { Teuchos::TimeMonitor timer(*_timerMvInit); MVT::MvInit( *Thyra_MV, alpha ); }
317
319
320
322 Teuchos::RCP< Thyra::MultiVectorBase<ScalarType> > getRCP() { return Thyra_MV; }
323
326 Teuchos::RCP< const Thyra::MultiVectorBase<ScalarType> > getRCP() const { return Thyra_MV; }
327
330 std::vector<Teuchos::RCP<Teuchos::Time> > getTimers() const {
331 std::vector<Teuchos::RCP<Teuchos::Time> > timers;
332 timers.push_back( _timerCreate );
333 timers.push_back( _timerClone );
334 timers.push_back( _timerDestroy );
335 timers.push_back( _timerMvTimesMatAddMv );
336 timers.push_back( _timerMvTransMv );
337 timers.push_back( _timerMvAddMv );
338 timers.push_back( _timerMvDot );
339 timers.push_back( _timerMvNorm );
340 timers.push_back( _timerMvScale );
341 timers.push_back( _timerSetBlock );
342 timers.push_back( _timerMvInit );
343 timers.push_back( _timerMvRandom );
344
345 return timers;
346 }
347
350 void copyTimers( const std::vector<Teuchos::RCP<Teuchos::Time> >& timers ) {
351 _timerCreate = timers[0];
352 _timerClone = timers[1];
353 _timerDestroy = timers[2];
354 _timerMvTimesMatAddMv = timers[3];
355 _timerMvTransMv = timers[4];
356 _timerMvAddMv = timers[5];
357 _timerMvDot = timers[6];
358 _timerMvNorm = timers[7];
359 _timerMvScale = timers[8];
360 _timerSetBlock = timers[9];
361 _timerMvInit = timers[10];
362 _timerMvRandom = timers[11];
363 }
365
367
369
371 void MvPrint( std::ostream& os ) const { MVT::MvPrint( *Thyra_MV, os ); }
373
374 private:
375
376 Teuchos::RCP<Thyra::MultiVectorBase<ScalarType> > Thyra_MV;
377 Teuchos::RCP<Teuchos::Time> _timerCreate, _timerClone, _timerDestroy;
378 Teuchos::RCP<Teuchos::Time> _timerMvTimesMatAddMv, _timerMvTransMv, _timerMvAddMv, _timerMvDot;
379 Teuchos::RCP<Teuchos::Time> _timerMvNorm, _timerMvScale, _timerSetBlock, _timerMvInit, _timerMvRandom;
380 };
381 //-------------------------------------------------------------
382
384 //
385 //--------template class AnasaziThyraOp---------------------
386 //
388
395 template<class ScalarType>
396 class ThyraOp : public virtual Operator<ScalarType> {
397 public:
398
399 typedef OperatorTraits<ScalarType,Thyra::MultiVectorBase<ScalarType>,Thyra::LinearOpBase<ScalarType> > OPT;
400
402
403
405 ThyraOp(const Teuchos::RCP<const Thyra::LinearOpBase<ScalarType> > &Op ) { Thyra_Op = Op; }
406
410
412
413
418 {
419 const Anasazi::ThyraMultiVec<ScalarType>* vec_X = dynamic_cast<const Anasazi::ThyraMultiVec<ScalarType>* >(&X);
421 OPT::Apply( *Thyra_Op, *(vec_X->getRCP()), *(vec_Y->getRCP()) );
422 }
423
425
426 private:
427 Teuchos::RCP<const Thyra::LinearOpBase<ScalarType> > Thyra_Op;
428 };
429
430} // end of Anasazi namespace
431
432#endif
433// end of file ANASAZI_THYRA_DEBUG_ADAPTER_HPP
Anasazi header file which uses auto-configuration information to include necessary C++ headers.
Interface for multivectors used by Anasazi' linear solvers.
Templated virtual class for creating operators that can interface with the Anasazi::OperatorTraits cl...
Specializations of the Anasazi multi-vector and operator traits classes using Thyra base classes Line...
Types and exceptions used within Anasazi solvers and interfaces.
Template specialization of Anasazi::MultiVecTraits class using the Thyra::MultiVectorBase class.
static void MvTimesMatAddMv(const ScalarType alpha, const TMVB &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, TMVB &mv)
Update mv with .
static void MvRandom(TMVB &mv)
Replace the vectors in mv with random vectors.
static Teuchos::RCP< const TMVB > CloneView(const TMVB &mv, const std::vector< int > &index)
Creates a new const MultiVectorBase that shares the selected contents of mv (shallow copy).
static Teuchos::RCP< TMVB > CloneViewNonConst(TMVB &mv, const std::vector< int > &index)
Creates a new MultiVectorBase that shares the selected contents of mv (shallow copy).
static void SetBlock(const TMVB &A, const std::vector< int > &index, TMVB &mv)
Copy the vectors in A to a set of vectors in mv indicated by the indices given in index.
static void MvTransMv(const ScalarType alpha, const TMVB &A, const TMVB &mv, Teuchos::SerialDenseMatrix< int, ScalarType > &B)
Compute a dense matrix B through the matrix-matrix multiply .
static Teuchos::RCP< TMVB > Clone(const TMVB &mv, const int numvecs)
Creates a new empty MultiVectorBase containing numvecs columns.
static void MvInit(TMVB &mv, ScalarType alpha=Teuchos::ScalarTraits< ScalarType >::zero())
Replace each element of the vectors in mv with alpha.
static ptrdiff_t GetGlobalLength(const TMVB &mv)
Obtain the vector length of mv.
static void MvAddMv(const ScalarType alpha, const TMVB &A, const ScalarType beta, const TMVB &B, TMVB &mv)
Replace mv with .
static void MvScale(TMVB &mv, const ScalarType alpha)
Scale each element of the vectors in *this with alpha.
static Teuchos::RCP< TMVB > CloneCopy(const TMVB &mv)
Creates a new MultiVectorBase and copies contents of mv into the new vector (deep copy).
static void MvDot(const TMVB &mv, const TMVB &A, std::vector< ScalarType > &b)
Compute a vector b where the components are the individual dot-products of the i-th columns of A and ...
static int GetNumberVecs(const TMVB &mv)
Obtain the number of vectors in mv.
static void MvPrint(const TMVB &mv, std::ostream &os)
Print the mv multi-vector to the os output stream.
static void MvNorm(const TMVB &mv, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec)
Compute the 2-norm of each individual vector of mv. Upon return, normvec[i] holds the value of ,...
Traits class which defines basic operations on multivectors.
Interface for multivectors used by Anasazi's linear solvers.
Template specialization of Anasazi::OperatorTraits class using the Thyra::LinearOpBase virtual base c...
static void Apply(const Thyra::LinearOpBase< ScalarType > &Op, const Thyra::MultiVectorBase< ScalarType > &x, Thyra::MultiVectorBase< ScalarType > &y)
This method takes the MultiVectorBase x and applies the LinearOpBase Op to it resulting in the MultiV...
Virtual base class which defines basic traits for the operator type.
Anasazi's templated virtual class for constructing an operator that can interface with the OperatorTr...
Basic adapter class for Anasazi::MultiVec that uses Thyra::MultiVectorBase<ScalarType>.
std::vector< Teuchos::RCP< Teuchos::Time > > getTimers() const
Return a std::vector<> of timers held by this object.
ThyraMultiVec(const Teuchos::RCP< Thyra::MultiVectorBase< ScalarType > > &mv)
Basic ThyraMultiVec constructor (wraps Thyra::MultiVectorBase<> object).
void MvAddMv(ScalarType alpha, const MultiVec< ScalarType > &A, ScalarType beta, const MultiVec< ScalarType > &B)
Replace *this with .
MultiVec< ScalarType > * CloneCopy() const
Creates a new ThyraMultiVec and copies contents of *this into the new vector (deep copy).
int GetNumberVecs() const
Obtain the vector length of *this.
Teuchos::RCP< Thyra::MultiVectorBase< ScalarType > > getRCP()
Return the reference-counted pointer held by this object.
void copyTimers(const std::vector< Teuchos::RCP< Teuchos::Time > > &timers)
Copy a std::vector<> of timers into this object.
virtual ~ThyraMultiVec()
Destructor.
void SetBlock(const MultiVec< ScalarType > &A, const std::vector< int > &index)
Copy the vectors in A to a set of vectors in *this.
void MvDot(const MultiVec< ScalarType > &A, std::vector< ScalarType > &b) const
Compute a vector b where the components are the individual dot-products, i.e. where A[i] is the i-th...
void MvTimesMatAddMv(ScalarType alpha, const MultiVec< ScalarType > &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, ScalarType beta)
Update *this with .
void MvInit(ScalarType alpha)
Replace each element of the vectors in *this with alpha.
ThyraMultiVec(const Teuchos::RCP< Thyra::MultiVectorBase< ScalarType > > &mv, std::vector< Teuchos::RCP< Teuchos::Time > > &timers)
Basic ThyraMultiVec constructor (wraps Thyra::MultiVectorBase<> object).
void MvPrint(std::ostream &os) const
Print *this ThyraMultiVec.
MultiVec< ScalarType > * CloneCopy(const std::vector< int > &index) const
Creates a new ThyraMultiVec and copies the selected contents of *this into the new vector (deep copy)...
Teuchos::RCP< const Thyra::MultiVectorBase< ScalarType > > getRCP() const
Return the const reference-counted pointer held by this object.
void MvNorm(std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec) const
Compute the 2-norm of each individual vector of *this. Upon return, normvec[i] holds the 2-norm of th...
void MvTransMv(ScalarType alpha, const MultiVec< ScalarType > &A, Teuchos::SerialDenseMatrix< int, ScalarType > &B) const
Compute a dense matrix B through the matrix-matrix multiply .
void MvScale(ScalarType alpha)
Scale each element of the vectors in *this with alpha.
MultiVec< ScalarType > * CloneViewNonConst(const std::vector< int > &index)
Creates a new ThyraMultiVec that shares the selected contents of *this.
void MvScale(const std::vector< ScalarType > &alpha)
Scale each element of the i-th vector in *this with alpha[i].
ptrdiff_t GetGlobalLength() const
Obtain the number of vectors in *this.
void MvRandom()
Fill the vectors in *this with random numbers.
const MultiVec< ScalarType > * CloneView(const std::vector< int > &index) const
Creates a new ThyraMultiVec that shares the selected contents of *this.
MultiVec< ScalarType > * Clone(const int numvecs) const
Creates a new empty ThyraMultiVec containing numvecs columns.
ThyraMultiVec(const ThyraMultiVec< ScalarType > &mv)
Copy constructor.
Basic adapter class for Anasazi::Operator that uses Thyra_Operator.
ThyraOp(const Teuchos::RCP< const Thyra::LinearOpBase< ScalarType > > &Op)
Basic constructor. Accepts reference-counted pointer to an Thyra_Operator.
void Apply(const MultiVec< ScalarType > &X, MultiVec< ScalarType > &Y) const
This method takes the Anasazi::MultiVec X and applies the operator to it resulting in the Anasazi::Mu...
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package.
ConjType
Enumerated types used to specify conjugation arguments.