13 #ifndef __Belos_SimpleOrthoManager_hpp
14 #define __Belos_SimpleOrthoManager_hpp
34 template<
class Scalar,
class MV>
60 #ifdef BELOS_TEUCHOS_TIME_MONITOR
77 makeTimer (
const std::string& prefix,
78 const std::string& timerName)
80 const std::string timerLabel =
81 prefix.empty() ? timerName : (prefix +
": " + timerName);
84 #endif // BELOS_TEUCHOS_TIME_MONITOR
98 using Teuchos::parameterList;
101 const std::string defaultNormalizationMethod (
"MGS");
102 const bool defaultReorthogonalization =
false;
105 RCP<ParameterList> params = parameterList (
"Simple");
106 params->set (
"Normalization", defaultNormalizationMethod,
107 "Which normalization method to use. Valid values are \"MGS\""
108 " (for Modified Gram-Schmidt) and \"CGS\" (for Classical "
110 params->set (
"Reorthogonalization", defaultReorthogonalization,
111 "Whether to perform one (unconditional) reorthogonalization "
127 using Teuchos::parameterList;
131 const std::string fastNormalizationMethod (
"CGS");
132 const bool fastReorthogonalization =
false;
136 fastParams->set (
"Normalization", fastNormalizationMethod);
137 fastParams->set (
"Reorthogonalization", fastReorthogonalization);
146 using Teuchos::parameterList;
151 RCP<ParameterList> params;
153 params = parameterList (*defaultParams);
158 const std::string normalizeImpl = params->get<std::string>(
"Normalization");
159 const bool reorthogonalize = params->get<
bool>(
"Reorthogonalization");
161 if (normalizeImpl ==
"MGS" ||
162 normalizeImpl ==
"Mgs" ||
163 normalizeImpl ==
"mgs") {
165 params->set (
"Normalization", std::string (
"MGS"));
168 params->set (
"Normalization", std::string (
"CGS"));
186 const std::string& label,
191 #ifdef BELOS_TEUCHOS_TIME_MONITOR
192 timerOrtho_ = makeTimer (label,
"All orthogonalization");
193 timerProject_ = makeTimer (label,
"Projection");
194 timerNormalize_ = makeTimer (label,
"Normalization");
195 #endif // BELOS_TEUCHOS_TIME_MONITOR
201 dbg <<
"Belos::SimpleOrthoManager constructor:" << endl
202 <<
"-- Normalization method: "
203 << (
useMgs_ ?
"MGS" :
"CGS") << endl
204 <<
"-- Reorthogonalize (unconditionally)? "
215 #ifdef BELOS_TEUCHOS_TIME_MONITOR
216 timerOrtho_ = makeTimer (label,
"All orthogonalization");
217 timerProject_ = makeTimer (label,
"Projection");
218 timerNormalize_ = makeTimer (label,
"Normalization");
219 #endif // BELOS_TEUCHOS_TIME_MONITOR
231 void norm (
const MV& X, std::vector<magnitude_type>& normVec)
const {
235 if (normVec.size () <
static_cast<size_t> (numCols)) {
236 normVec.resize (numCols);
246 #ifdef BELOS_TEUCHOS_TIME_MONITOR
249 #endif // BELOS_TEUCHOS_TIME_MONITOR
256 for (
int k = 0; k < Q.size(); ++k)
264 #ifdef BELOS_TEUCHOS_TIME_MONITOR
267 #endif // BELOS_TEUCHOS_TIME_MONITOR
298 for (
int k = 0; k < ncols; ++k) {
309 mat_type X1_T_X2 (ncols_X1, ncols_X2);
335 }
else if (
B->numRows () != numCols ||
B->numCols () != numCols) {
336 B->shape (numCols, numCols);
340 std::vector<magnitude_type> normVec (1);
341 for (
int j = 0; j < numCols; ++j) {
344 for (
int i = 0; i < j; ++i) {
346 const MV& X_i = *X_prv;
354 const Scalar B_ij_first = (*B)(i, j);
357 (*B)(i, j) += B_ij_first;
363 (*B)(j, j) = theNorm;
389 }
else if (B->numRows() != numCols || B->numCols() != numCols) {
390 B->shape (numCols, numCols);
395 std::vector<magnitude_type> normVec (1);
404 norm (*X_cur, normVec);
406 B_ref(0,0) = theNorm;
408 const Scalar invNorm =
STS::one () / theNorm;
417 for (
int j = 1; j < numCols; ++j) {
431 B_prvcur += B2_prvcur;
434 norm (*X_cur, normVec);
436 B_ref(j,j) = theNorm;
438 const Scalar invNorm =
STS::one () / theNorm;
453 const bool attemptToRecycle =
true)
const
457 const int num_Q_blocks = Q.size();
462 int numAllocated = 0;
463 if (attemptToRecycle) {
464 for (
int i = 0; i < num_Q_blocks; ++i) {
475 Ci.
shape (ncols_Qi, ncols_X);
485 for (
int i = 0; i < num_Q_blocks; ++i) {
494 dbg <<
"SimpleOrthoManager::allocateProjectionCoefficients: "
495 <<
"Allocated " << numAllocated <<
" blocks out of "
496 << num_Q_blocks << endl;
506 const int num_Q_blocks = Q.size();
507 for (
int i = 0; i < num_Q_blocks; ++i) {
509 const MV& Qi = *Q[i];
518 #endif // __Belos_SimpleOrthoManager_hpp
void project(MV &X, Teuchos::Array< mat_ptr > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
void innerProd(const MV &X, const MV &Y, mat_type &Z) const
Provides the inner product defining the orthogonality concepts.
void allocateProjectionCoefficients(Teuchos::Array< mat_ptr > &C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q, const MV &X, const bool attemptToRecycle=true) const
magnitude_type orthonormError(const MV &X) const
This method computes the error in orthonormality of a multivector.
virtual ~SimpleOrthoManager()
Virtual destructor for memory safety of derived classes.
Class which manages the output and verbosity of the Belos solvers.
bool is_null(const boost::shared_ptr< T > &p)
int normalize(MV &X, mat_ptr B) const
int normalizeCgs(MV &X, mat_ptr B) const
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitude_type
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, Scalar > > mat_ptr
static Teuchos::RCP< const MV > CloneView(const MV &mv, const std::vector< int > &index)
Creates a new const MV that shares the selected contents of mv (shallow copy).
Declaration of basic traits for the multivector type.
void setLabel(const std::string &label)
This method sets the label used by the timers in the orthogonalization manager.
SimpleOrthoManager(const Teuchos::RCP< OutputManager< Scalar > > &outMan, const std::string &label, const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Constructor.
Teuchos::ScalarTraits< Scalar > STS
static void MvTransMv(const ScalarType alpha, const MV &A, const MV &mv, Teuchos::SerialDenseMatrix< int, ScalarType > &B)
Compute a dense matrix B through the matrix-matrix multiply .
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
static int GetNumberVecs(const MV &mv)
Obtain the number of vectors in mv.
Teuchos::RCP< OutputManager< Scalar > > outMan_
Output manager (used mainly for debugging).
Traits class which defines basic operations on multivectors.
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...
MultiVecTraits< Scalar, MV > MVT
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters()
Get a "fast" list of parameters.
static Teuchos::RCP< MV > CloneViewNonConst(MV &mv, const std::vector< int > &index)
Creates a new MV that shares the selected contents of mv (shallow copy).
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool is_null(const RCP< T > &p)
Simple OrthoManager implementation for benchmarks.
Teuchos::ScalarTraits< magnitude_type > STM
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get a default list of parameters.
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
void norm(const MV &X, std::vector< magnitude_type > &normVec) const
void setMyParamList(const RCP< ParameterList > ¶mList)
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
Teuchos::SerialDenseMatrix< int, Scalar > mat_type
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
void resize(size_type new_size, const value_type &x=value_type())
Teuchos::RCP< Teuchos::ParameterList > defaultParams_
Default parameter list.
bool useMgs_
Whether to use MGS or CGS in the normalize() step.
SimpleOrthoManager(const std::string &label="Belos")
Constructor.
void rawProject(MV &X, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q, Teuchos::ArrayView< mat_ptr > C) const
OrdinalType numCols() const
Templated virtual class for providing orthogonalization/orthonormalization methods.
std::string label_
Label for Belos timer display.
int normalizeMgs(MV &X, Teuchos::RCP< Teuchos::SerialDenseMatrix< int, Scalar > > B) const
static void MvNorm(const MV &mv, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec, NormType type=TwoNorm)
Compute the norm of each individual vector of mv. Upon return, normvec[i] holds the value of ...
static void MvScale(MV &mv, const ScalarType alpha)
Scale each element of the vectors in mv with alpha.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &plist)
int shape(OrdinalType numRows, OrdinalType numCols)
magnitude_type orthogError(const MV &X1, const MV &X2) const
This method computes the error in orthogonality of two multivectors.
Belos header file which uses auto-configuration information to include necessary C++ headers...
virtual int projectAndNormalizeImpl(MV &X, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
bool reorthogonalize_
Whether or not to do (unconditional) reorthogonalization.
OrdinalType numRows() const
const std::string & getLabel() const
This method returns the label being used by the timers in the orthogonalization manager.