Anasazi  Version of the Day
AnasaziTraceMinSolMgr.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, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
25 //
26 // ***********************************************************************
27 // @HEADER
28 
29 #ifndef ANASAZI_TRACEMIN_SOLMGR_HPP
30 #define ANASAZI_TRACEMIN_SOLMGR_HPP
31 
38 #include "AnasaziConfigDefs.hpp"
39 #include "AnasaziTypes.hpp"
40 
41 #include "AnasaziEigenproblem.hpp"
42 #include "AnasaziSolverUtils.hpp"
43 
44 #include "AnasaziTraceMin.hpp"
46 #include "AnasaziBasicSort.hpp"
52 #include "Teuchos_BLAS.hpp"
53 #include "Teuchos_LAPACK.hpp"
54 #include "Teuchos_TimeMonitor.hpp"
55 #ifdef TEUCHOS_DEBUG
56 # include <Teuchos_FancyOStream.hpp>
57 #endif
58 #ifdef HAVE_MPI
59 #include <mpi.h>
60 #endif
61 
62 
63 namespace Anasazi {
64 namespace Experimental {
65 
66 template<class ScalarType, class MV, class OP>
67 
100 class TraceMinSolMgr : public TraceMinBaseSolMgr<ScalarType,MV,OP> {
101 
102  private:
105  typedef Teuchos::ScalarTraits<ScalarType> SCT;
106  typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
107  typedef Teuchos::ScalarTraits<MagnitudeType> MT;
108 
109  public:
110 
112 
113 
124  TraceMinSolMgr( const Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > &problem,
125  Teuchos::ParameterList &pl );
127 
128  private:
129 
130  int maxits_;
131 
132  // Test whether we have exceeded the maximum number of iterations
133  bool exceededMaxIter() { return (this->iter_ >= maxits_); };
134 
135  // TraceMin does not restart, so this will always return false
136  bool needToRestart(const Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > solver) { return false; };
137 
138  // TraceMin does not restart, so this will throw an exception
139  bool performRestart(int &numRestarts, Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > solver)
140  { TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "Anasazi::TraceMinSolMgr::performRestart(): TraceMin does not perform restarts!"); };
141 
142  // Returns a new TraceMin solver object
143  Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > createSolver(
144  const Teuchos::RCP<SortManager<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > &sorter,
145  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &outputtest,
146  const Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > &ortho,
147  Teuchos::ParameterList &plist
148  );
149 };
150 
151 
153 // Constructor - accepts maximum iterations in addition to the other parameters of the abstract base class
154 template<class ScalarType, class MV, class OP>
155 TraceMinSolMgr<ScalarType,MV,OP>::TraceMinSolMgr( const Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > &problem, Teuchos::ParameterList &pl ) :
156  TraceMinBaseSolMgr<ScalarType,MV,OP>(problem,pl)
157 {
158  // Get the maximum number of iterations
159  maxits_ = pl.get("Maximum Iterations", 100);
160  TEUCHOS_TEST_FOR_EXCEPTION(maxits_ < 1, std::invalid_argument, "Anasazi::TraceMinSolMgr::constructor(): \"Maximum Iterations\" must be strictly positive.");
161 
162  // block size: default is 2* nev()
163  // TODO: Find out minimum value
164  this->blockSize_ = pl.get("Block Size",2*this->problem_->getNEV());
165  TEUCHOS_TEST_FOR_EXCEPTION(this->blockSize_ < this->problem_->getNEV(), std::invalid_argument,
166  "Anasazi::TraceMinSolMgr::constructor(): \"Block Size\" must be greater than or equal to the number of desired eigenpairs.");
167 
168  this->useHarmonic_ = pl.get("Use Harmonic Ritz Values", false);
169  TEUCHOS_TEST_FOR_EXCEPTION(this->useHarmonic_, std::invalid_argument,
170  "Anasazi::TraceMinSolMgr::constructor(): Please disable the harmonic Ritz values. It doesn't make sense to use them with TraceMin, which does not use expanding subspaces. Perhaps you wanted TraceMin-Davidson?");
171 
172  // TraceMin does not restart, so the number of blocks and number of restart blocks will always be 1
173  this->numBlocks_ = 1;
174  this->numRestartBlocks_ = 1;
175 
176  TEUCHOS_TEST_FOR_EXCEPTION(static_cast<ptrdiff_t>(this->numBlocks_)*this->blockSize_ + this->maxLocked_ > MVT::GetGlobalLength(*this->problem_->getInitVec()),
177  std::invalid_argument,
178  "Anasazi::TraceMinSolMgr::constructor(): Potentially impossible orthogonality requests. Reduce basis size or locking size.");
179 
180  TEUCHOS_TEST_FOR_EXCEPTION(this->maxLocked_ + this->blockSize_ < this->problem_->getNEV(), std::invalid_argument,
181  "Anasazi::TraceMinDavidsonSolMgr: Not enough storage space for requested number of eigenpairs.");
182 }
183 
184 
186 // Returns a new TraceMin solver object
187 template <class ScalarType, class MV, class OP>
188 Teuchos::RCP< TraceMinBase<ScalarType,MV,OP> > TraceMinSolMgr<ScalarType,MV,OP>::createSolver(
189  const Teuchos::RCP<SortManager<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > &sorter,
190  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &outputtest,
191  const Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > &ortho,
192  Teuchos::ParameterList &plist
193  )
194 {
195  return Teuchos::rcp( new TraceMin<ScalarType,MV,OP>(this->problem_,sorter,this->printer_,outputtest,ortho,plist) );
196 }
197 
198 
199 }} // end Anasazi namespace
200 
201 #endif /* ANASAZI_TRACEMIN_SOLMGR_HPP */
static ptrdiff_t GetGlobalLength(const MV &mv)
Return the number of rows in the given multivector mv.
This class implements a TraceMIN iteration, a preconditioned iteration for solving linear symmetric p...
This class defines the interface required by an eigensolver and status test class to compute solution...
Virtual base class which defines basic traits for the operator type.
Basic implementation of the Anasazi::SortManager class.
The Anasazi::TraceMinBaseSolMgr provides an abstract base class for the TraceMin series of solver man...
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package...
A status test for testing the norm of the eigenvectors residuals along with a set of auxiliary eigenv...
Basic output manager for sending information of select verbosity levels to the appropriate output str...
Anasazi&#39;s templated virtual class for providing routines for orthogonalization and orthonormalization...
TraceMinSolMgr(const Teuchos::RCP< Eigenproblem< ScalarType, MV, OP > > &problem, Teuchos::ParameterList &pl)
Basic constructor for TraceMinSolMgr.
Abstract base class which defines the interface required by an eigensolver and status test class to c...
A status test for testing the norm of the eigenvectors residuals.
Traits class which defines basic operations on multivectors.
Anasazi header file which uses auto-configuration information to include necessary C++ headers...
The Anasazi::TraceMinBaseSolMgr provides an abstract base class for the TraceMin series of solver man...
The Anasazi::TraceMinSolMgr provides a flexible solver manager over the TraceMin eigensolver.
Special StatusTest for printing status tests.
Status test for forming logical combinations of other status tests.
Types and exceptions used within Anasazi solvers and interfaces.
This is an abstract base class for the trace minimization eigensolvers.
Anasazi&#39;s templated pure virtual class for managing the sorting of approximate eigenvalues computed b...
Common interface of stopping criteria for Anasazi&#39;s solvers.
Implementation of the trace minimization eigensolver.
Class which provides internal utilities for the Anasazi solvers.