Anasazi  Version of the Day
AnasaziStatusTestMaxIters.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 
30 #ifndef ANASAZI_STATUS_TEST_MAXITER_HPP
31 #define ANASAZI_STATUS_TEST_MAXITER_HPP
32 
39 #include "AnasaziStatusTest.hpp"
40 
41 
60 namespace Anasazi {
61 
62 
63 template <class ScalarType, class MV, class OP>
64 class StatusTestMaxIters : public StatusTest<ScalarType,MV,OP> {
65 
66  public:
68 
69 
71  StatusTestMaxIters(int maxIter, bool negate = false) : state_(Undefined), negate_(negate) {
72  setMaxIters(maxIter);
73  };
74 
76  virtual ~StatusTestMaxIters() {};
78 
80 
81 
86  state_ = (solver->getNumIters() >= maxIters_) ? Passed : Failed;
87  if (negate_) {
88  if (state_ == Passed) state_ = Failed;
89  else state_ = Passed;
90  }
91  return state_;
92  }
93 
96  return state_;
97  }
98 
100  std::vector<int> whichVecs() const {
101  return std::vector<int>(0);
102  }
103 
105  int howMany() const {
106  return 0;
107  }
108 
110 
112 
113 
117  void setMaxIters(int maxIters) {
118  state_ = Undefined;
119  maxIters_ = maxIters;
120  }
121 
123  int getMaxIters() {return maxIters_;}
124 
128  void setNegate(bool negate) {
129  state_ = Undefined;
130  negate_ = negate;
131  }
132 
134  bool getNegate() const {
135  return negate_;
136  }
137 
139 
141 
142 
148  void reset() {
149  state_ = Undefined;
150  }
151 
153 
158  void clearStatus() {
159  state_ = Undefined;
160  }
161 
163 
165 
166 
168  std::ostream& print(std::ostream& os, int indent = 0) const {
169  std::string ind(indent,' ');
170  os << ind << "- StatusTestMaxIters: ";
171  switch (state_) {
172  case Passed:
173  os << "Passed" << std::endl;
174  break;
175  case Failed:
176  os << "Failed" << std::endl;
177  break;
178  case Undefined:
179  os << "Undefined" << std::endl;
180  break;
181  }
182  os << ind << " MaxIters: " << maxIters_ << std::endl;
183  return os;
184  }
185 
187  private:
188  int maxIters_;
189  TestStatus state_;
190  bool negate_;
191 
192 };
193 
194 } // end of Anasazi namespace
195 
196 #endif /* ANASAZI_STATUS_TEST_MAXITER_HPP */
std::vector< int > whichVecs() const
Get the indices for the vectors that passed the test.
int getMaxIters()
Get the maximum number of iterations.
TestStatus
Enumerated type used to pass back information from a StatusTest.
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package...
StatusTestMaxIters(int maxIter, bool negate=false)
Constructor.
void clearStatus()
Clears the results of the last status test.
void setNegate(bool negate)
Set the negation policy for the status test.
void reset()
Informs the status test that it should reset its internal configuration to the uninitialized state...
TestStatus getStatus() const
Return the result of the most recent checkStatus call.
A status test for testing the number of iterations.
void setMaxIters(int maxIters)
Set the maximum number of iterations.
std::ostream & print(std::ostream &os, int indent=0) const
Output formatted description of stopping test to output stream.
TestStatus checkStatus(Eigensolver< ScalarType, MV, OP > *solver)
Check status as defined by test.
Common interface of stopping criteria for Anasazi&#39;s solvers.
int howMany() const
Get the number of vectors that passed the test.
virtual int getNumIters() const =0
Get the current iteration count.
bool getNegate() const
Get the negation policy for the status test.
The Eigensolver is a templated virtual base class that defines the basic interface that any eigensolv...
Declaration and definition of Anasazi::StatusTest.