Belos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BelosTsqrOrthoManager.hpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // Belos: Block Linear Solvers Package
5 // Copyright 2004 Sandia Corporation
6 //
7 // Under the 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 
44 
45 #ifndef __BelosTsqrOrthoManager_hpp
46 #define __BelosTsqrOrthoManager_hpp
47 
49 // Belos doesn't have an SVQB orthomanager implemented yet, so we just
50 // use a default orthomanager for the case where the inner product
51 // matrix is nontrivial.
53 
54 
55 namespace Belos {
56 
78 template<class Scalar, class MV>
80 public:
81  typedef Scalar scalar_type;
85  typedef MV multivector_type;
86 
89 
98  virtual int
99  normalizeOutOfPlace (MV& X, MV& Q, mat_ptr B) const = 0;
100 
119  virtual int
121  MV& X_out,
123  mat_ptr B,
125 
128 };
129 
136 template<class Scalar, class MV>
138  public OrthoManager<Scalar, MV>,
139  public OutOfPlaceNormalizerMixin<Scalar, MV>,
141 {
142 public:
143  typedef Scalar scalar_type;
146  typedef MV multivector_type;
147 
150 
152  impl_.setParameterList (params);
153  }
154 
156  return impl_.getNonconstParameterList ();
157  }
158 
160  return impl_.unsetParameterList ();
161  }
162 
171  return impl_.getValidParameters();
172  }
173 
184  return impl_.getFastParameters();
185  }
186 
203  const std::string& label = "Belos") :
204  impl_ (params, label)
205  {}
206 
211  TsqrOrthoManager (const std::string& label) :
212  impl_ (label)
213  {}
214 
216  virtual ~TsqrOrthoManager() {}
217 
239  void
241  {
242  impl_.setReorthogonalizationCallback (callback);
243  }
244 
245  void innerProd (const MV &X, const MV &Y, mat_type& Z) const {
246  return impl_.innerProd (X, Y, Z);
247  }
248 
249  void norm (const MV& X, std::vector<magnitude_type>& normVec) const {
250  return impl_.norm (X, normVec);
251  }
252 
253  void
254  project (MV &X,
257  {
258  return impl_.project (X, C, Q);
259  }
260 
261  int
262  normalize (MV &X, mat_ptr B) const
263  {
264  return impl_.normalize (X, B);
265  }
266 
267 protected:
268  virtual int
271  mat_ptr B,
273  {
274  return impl_.projectAndNormalize (X, C, B, Q);
275  }
276 
277 public:
294  int
295  normalizeOutOfPlace (MV& X, MV& Q, mat_ptr B) const
296  {
297  return impl_.normalizeOutOfPlace (X, Q, B);
298  }
299 
320  int
322  MV& X_out,
324  mat_ptr B,
326  {
327  return impl_.projectAndNormalizeOutOfPlace (X_in, X_out, C, B, Q);
328  }
329 
330  magnitude_type orthonormError (const MV &X) const {
331  return impl_.orthonormError (X);
332  }
333 
334  magnitude_type orthogError (const MV &X1, const MV &X2) const {
335  return impl_.orthogError (X1, X2);
336  }
337 
345  void setLabel (const std::string& label) {
346  impl_.setLabel (label);
347  }
348 
349  const std::string& getLabel() const { return impl_.getLabel(); }
350 
351 private:
357  mutable TsqrOrthoManagerImpl<Scalar, MV> impl_;
358 
360  std::string label_;
361 };
362 
363 
377 template<class Scalar, class MV, class OP>
379  public MatOrthoManager<Scalar, MV, OP>,
380  public OutOfPlaceNormalizerMixin<Scalar, MV>,
382 {
383 public:
384  typedef Scalar scalar_type;
387  typedef MV multivector_type;
389  typedef OP operator_type;
390 
393 
394 private:
404 
408 
412 
416 
417 public:
439  const std::string& label = "Belos",
440  Teuchos::RCP<const OP> Op = Teuchos::null) :
441  MatOrthoManager<Scalar, MV, OP> (Op),
442  tsqr_ (params, label),
443  pDgks_ (Teuchos::null) // Initialized lazily
444  {}
445 
454  TsqrMatOrthoManager (const std::string& label = "Belos",
455  Teuchos::RCP<const OP> Op = Teuchos::null) :
456  MatOrthoManager<Scalar, MV, OP> (Op),
457  tsqr_ (label),
458  pDgks_ (Teuchos::null) // Initialized lazily
459  {}
460 
462  virtual ~TsqrMatOrthoManager() {}
463 
472  return tsqr_.getValidParameters ();
473  }
474 
485  return tsqr_.getFastParameters ();
486  }
487 
489  tsqr_.setParameterList (params);
490  }
491 
492  const std::string& getLabel() const { return tsqr_.getLabel (); }
493 
494  void
496  {
497  // We override the base class' setOp() so that the
498  // DGKSOrthoManager instance gets the new op.
499  //
500  // The base_type notation helps C++ resolve the name for a
501  // member function of a templated base class.
502  base_type::setOp (Op); // base class gets a copy of the Op too
503 
504  if (! Op.is_null()) {
505  ensureDgksInit (); // Make sure the DGKS object has been initialized
506  pDgks_->setOp (Op);
507  }
508  }
509 
511  // The base_type notation helps C++ resolve the name for a
512  // member function of a templated base class.
513  return base_type::getOp();
514  }
515 
516  void
517  project (MV &X,
518  Teuchos::RCP<MV> MX,
521  {
522  if (getOp().is_null()) {
523  tsqr_.project (X, C, Q);
524  if (! MX.is_null()) {
525  // MX gets a copy of X; M is the identity operator.
526  MVT::Assign (X, *MX);
527  }
528  } else {
529  ensureDgksInit ();
530  pDgks_->project (X, MX, C, Q);
531  }
532  }
533 
534  void
535  project (MV &X,
538  {
539  project (X, Teuchos::null, C, Q);
540  }
541 
542  int
543  normalize (MV& X, Teuchos::RCP<MV> MX, mat_ptr B) const
544  {
545  if (getOp().is_null()) {
546  const int rank = tsqr_.normalize (X, B);
547  if (! MX.is_null()) {
548  // MX gets a copy of X; M is the identity operator.
549  MVT::Assign (X, *MX);
550  }
551  return rank;
552  } else {
553  ensureDgksInit ();
554  return pDgks_->normalize (X, MX, B);
555  }
556  }
557 
558  int normalize (MV& X, mat_ptr B) const {
559  return normalize (X, Teuchos::null, B);
560  }
561 
562  // Attempted fix for a warning about hiding
563  // OrthoManager::projectAndNormalize(). Unfortunately, this fix turns out
564  // to produce a compilation error with cray++, see bug #6129,
565  // <https://software.sandia.gov/bugzilla/show_bug.cgi?id=6129>.
566  //using Belos::OrthoManager<Scalar, MV>::projectAndNormalize;
567 
568 protected:
569  virtual int
571  Teuchos::RCP<MV> MX,
573  mat_ptr B,
575  {
576  if (getOp().is_null()) {
577  const int rank = tsqr_.projectAndNormalize (X, C, B, Q);
578  if (! MX.is_null()) {
579  // MX gets a copy of X; M is the identity operator.
580  MVT::Assign (X, *MX);
581  }
582  return rank;
583  } else {
584  ensureDgksInit ();
585  return pDgks_->projectAndNormalize (X, MX, C, B, Q);
586  }
587  }
588 
589 public:
590  int
591  normalizeOutOfPlace (MV& X, MV& Q, mat_ptr B) const
592  {
593  if (getOp().is_null()) {
594  return tsqr_.normalizeOutOfPlace (X, Q, B);
595  } else {
596  // DGKS normalizes in place, so we have to copy.
597  ensureDgksInit ();
598  const int rank = pDgks_->normalize (X, B);
599  MVT::Assign (X, Q);
600  return rank;
601  }
602  }
603 
604  int
606  MV& X_out,
608  mat_ptr B,
610  {
611  using Teuchos::null;
612 
613  if (getOp().is_null()) {
614  return tsqr_.projectAndNormalizeOutOfPlace (X_in, X_out, C, B, Q);
615  } else {
616  // DGKS normalizes in place, so we have to copy.
617  ensureDgksInit ();
618  const int rank = pDgks_->projectAndNormalize (X_in, null, C, B, Q);
619  MVT::Assign (X_in, X_out);
620  return rank;
621  }
622  }
623 
625  orthonormError (const MV &X, Teuchos::RCP<const MV> MX) const
626  {
627  if (getOp().is_null()) {
628  return tsqr_.orthonormError (X); // Ignore MX
629  } else {
630  ensureDgksInit ();
631  return pDgks_->orthonormError (X, MX);
632  }
633  }
634 
635  magnitude_type orthonormError (const MV &X) const {
636  return orthonormError (X, Teuchos::null);
637  }
638 
639  magnitude_type orthogError (const MV &X1, const MV &X2) const {
640  return orthogError (X1, Teuchos::null, X2);
641  }
642 
644  orthogError (const MV &X1,
646  const MV &X2) const
647  {
648  if (getOp ().is_null ()) {
649  // Ignore MX1, since we don't need to write to it.
650  return tsqr_.orthogError (X1, X2);
651  } else {
652  ensureDgksInit ();
653  return pDgks_->orthogError (X1, MX1, X2);
654  }
655  }
656 
657  void
658  setLabel (const std::string& label)
659  {
660  tsqr_.setLabel (label);
661 
662  // Make sure DGKS gets the new label, if it's initialized.
663  // Otherwise, it will get the new label on initialization.
664  if (! pDgks_.is_null ()) {
665  pDgks_->setLabel (label);
666  }
667  }
668 
669 private:
671  void
672  ensureDgksInit () const
673  {
674  // NOTE (mfh 11 Jan 2011) DGKS has a parameter that needs to be
675  // set. For now, we just use the default value of the parameter.
676  if (pDgks_.is_null ()) {
677  pDgks_ = Teuchos::rcp (new dgks_type (getLabel (), getOp ()));
678  }
679  }
680 
688  mutable tsqr_type tsqr_;
689 
695  mutable Teuchos::RCP<dgks_type> pDgks_;
696 };
697 
698 } // namespace Belos
699 
700 #endif // __BelosTsqrOrthoManager_hpp
Teuchos::RCP< mat_type > mat_ptr
virtual int projectAndNormalizeOutOfPlace(MV &X_in, MV &X_out, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const =0
Project and normalize X_in into X_out.
void project(MV &X, Teuchos::RCP< MV > MX, Teuchos::Array< mat_ptr > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
int projectAndNormalize(MV &X, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q)
Project X against Q and normalize X.
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
Interface of callback invoked by TsqrOrthoManager on reorthogonalization.
virtual ~TsqrMatOrthoManager()
Destructor (declared virtual for memory safety of derived classes).
bool is_null(const boost::shared_ptr< T > &p)
virtual int projectAndNormalizeWithMxImpl(MV &X, Teuchos::RCP< MV > MX, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
int projectAndNormalizeOutOfPlace(MV &X_in, MV &X_out, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
Project and normalize X_in into X_out; overwrite X_in.
void project(MV &X, Teuchos::Array< mat_ptr > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q)
Compute and .
magnitude_type orthogError(const MV &X1, const MV &X2) const
Return the Frobenius norm of the inner product of X1 with itself.
void norm(const MV &X, std::vector< magnitude_type > &normVec) const
void project(MV &X, Teuchos::Array< mat_ptr > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
Mixin for out-of-place orthogonalization.
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters()
Get &quot;fast&quot; parameters for TsqrMatOrthoManager.
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set parameters from the given parameter list.
const std::string & getLabel() const
This method returns the label being used by the timers in the orthogonalization manager.
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitude_type
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters()
Get &quot;fast&quot; parameters for TsqrOrthoManagerImpl.
TSQR-based OrthoManager subclass implementation.
virtual ~OutOfPlaceNormalizerMixin()
Trivial virtual destructor, to silence compiler warnings.
int normalize(MV &X, mat_ptr B)
Orthogonalize the columns of X in place.
int normalize(MV &X, mat_ptr B) const
magnitude_type orthonormError(const MV &X, Teuchos::RCP< const MV > MX) const
This method computes the error in orthonormality of a multivector. The method has the option of explo...
OP operator_type
Operator type with which this class was specialized.
void setLabel(const std::string &label)
Set the label for timers.
Teuchos::RCP< mat_type > mat_ptr
void setLabel(const std::string &label)
Set the label for (the timers for) this orthogonalization manager, and create new timers if the label...
const std::string & getLabel() const
This method returns the label being used by the timers in the orthogonalization manager.
Teuchos::SerialDenseMatrix< int, Scalar > mat_type
static void Assign(const MV &A, MV &mv)
mv := A
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Default valid parameter list.
Traits class which defines basic operations on multivectors.
TsqrOrthoManager(const std::string &label)
Constructor (that sets default parameters).
int normalize(MV &X, Teuchos::RCP< MV > MX, mat_ptr B) const
Belos&#39;s templated virtual class for providing routines for orthogonalization and orthonormzalition of...
int normalizeOutOfPlace(MV &X, MV &Q, mat_ptr B) const
Normalize X into Q*B, overwriting X with invalid values.
Classical Gram-Schmidt (with DGKS correction) implementation of the Belos::OrthoManager class...
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitude_type
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void innerProd(const MV &X, const MV &Y, mat_type &Z) const
Provides the inner product defining the orthogonality concepts.
void setOp(Teuchos::RCP< const OP > Op)
void setReorthogonalizationCallback(const Teuchos::RCP< ReorthogonalizationCallback< Scalar > > &callback)
Set callback to be invoked on reorthogonalization.
virtual int normalizeOutOfPlace(MV &X, MV &Q, mat_ptr B) const =0
Normalize X into Q*B.
magnitude_type orthonormError(const MV &X) const
This method computes the error in orthonormality of a multivector.
const std::string & getLabel() const
Get the label for timers (if timers are enabled).
magnitude_type orthonormError(const MV &X) const
Return .
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get default parameters for TsqrMatOrthoManager.
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitude_type
int projectAndNormalizeOutOfPlace(MV &X_in, MV &X_out, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
Project and normalize X_in into X_out.
int normalizeOutOfPlace(MV &X, MV &Q, mat_ptr B) const
Normalize X into Q*B.
virtual ~TsqrOrthoManager()
Destructor, declared virtual for safe inheritance.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Default valid parameter list.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &params)
int normalize(MV &X, mat_ptr B) const
MV multivector_type
Multivector type with which this class was specialized.
Teuchos::SerialDenseMatrix< int, Scalar > mat_type
virtual int projectAndNormalizeImpl(MV &X, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
MV multivector_type
Multivector type with which this class was specialized.
void setLabel(const std::string &label)
This method sets the label used by the timers in the orthogonalization manager.
TsqrMatOrthoManager(const std::string &label="Belos", Teuchos::RCP< const OP > Op=Teuchos::null)
Constructor (that sets default parameters).
Teuchos::SerialDenseMatrix< int, Scalar > mat_type
Teuchos::RCP< const OP > getOp() const
Get operator.
TsqrMatOrthoManager(const Teuchos::RCP< Teuchos::ParameterList > &params, const std::string &label="Belos", Teuchos::RCP< const OP > Op=Teuchos::null)
Constructor (that sets user-specified parameters).
An implementation of the Belos::MatOrthoManager that performs orthogonalization using (potentially) m...
Orthogonalization manager back end based on Tall Skinny QR (TSQR)
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &params)
magnitude_type orthogError(const MV &X1, const MV &X2) const
This method computes the error in orthogonality of two multivectors. This method. ...
Belos&#39;s templated virtual class for providing routines for orthogonalization and orthonormzalition of...
int projectAndNormalizeOutOfPlace(MV &X_in, MV &X_out, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q)
Project and normalize X_in into X_out; overwrite X_in.
int normalizeOutOfPlace(MV &X, MV &Q, mat_ptr B)
Normalize X into Q*B, overwriting X.
MatOrthoManager subclass using TSQR or DGKS.
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters() const
Get &quot;fast&quot; parameters for TsqrOrthoManager.
Teuchos::RCP< const OP > getOp() const
void setOp(Teuchos::RCP< const OP > Op)
Set operator.
magnitude_type orthogError(const MV &X1, Teuchos::RCP< const MV > MX1, const MV &X2) const
This method computes the error in orthogonality of two multivectors. The method has the option of exp...
TsqrOrthoManager(const Teuchos::RCP< Teuchos::ParameterList > &params, const std::string &label="Belos")
Constructor (that sets user-specified parameters).
void project(MV &X, Teuchos::Array< mat_ptr > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
magnitude_type orthonormError(const MV &X) const
This method computes the error in orthonormality of a multivector.
TSQR-based OrthoManager subclass.
magnitude_type orthogError(const MV &X1, const MV &X2) const
This method computes the error in orthogonality of two multivectors.
bool is_null() const

Generated on Fri Jun 5 2020 10:20:48 for Belos by doxygen 1.8.5