18 #ifndef BELOS_IMGS_ORTHOMANAGER_MP_VECTOR_HPP
19 #define BELOS_IMGS_ORTHOMANAGER_MP_VECTOR_HPP
22 #include "BelosIMGSOrthoManager.hpp"
26 template<
class Storage,
class MV,
class OP>
27 class IMGSOrthoManager<Sacado::MP::Vector<Storage>,MV,OP> :
28 public MatOrthoManager<Sacado::MP::Vector<Storage>,MV,OP>
35 typedef MultiVecTraits<ScalarType,MV>
MVT;
36 typedef OperatorTraits<ScalarType,MV,OP>
OPT;
45 const int max_ortho_steps = max_ortho_steps_default_,
49 max_ortho_steps_( max_ortho_steps ),
51 sing_tol_( sing_tol ),
54 #ifdef BELOS_TEUCHOS_TIME_MONITOR
56 ss << label_ +
": IMGS[" << max_ortho_steps_ <<
"]";
58 std::string orthoLabel = ss.str() +
": Orthogonalization";
61 std::string updateLabel = ss.str() +
": Ortho (Update)";
64 std::string normLabel = ss.str() +
": Ortho (Norm)";
67 std::string ipLabel = ss.str() +
": Ortho (Inner Product)";
74 const std::string& label =
"Belos",
77 max_ortho_steps_ (max_ortho_steps_default_),
78 blk_tol_ (blk_tol_default_),
79 sing_tol_ (sing_tol_default_),
82 setParameterList (plist);
84 #ifdef BELOS_TEUCHOS_TIME_MONITOR
86 ss << label_ +
": IMGS[" << max_ortho_steps_ <<
"]";
88 std::string orthoLabel = ss.str() +
": Orthogonalization";
91 std::string updateLabel = ss.str() +
": Ortho (Update)";
94 std::string normLabel = ss.str() +
": Ortho (Norm)";
97 std::string ipLabel = ss.str() +
": Ortho (Inner Product)";
113 using Teuchos::parameterList;
116 RCP<const ParameterList> defaultParams = getValidParameters();
117 RCP<ParameterList> params;
119 params = parameterList (*defaultParams);
134 int maxNumOrthogPasses;
139 maxNumOrthogPasses = params->
get<
int> (
"maxNumOrthogPasses");
140 }
catch (InvalidParameterName&) {
141 maxNumOrthogPasses = defaultParams->get<
int> (
"maxNumOrthogPasses");
142 params->set (
"maxNumOrthogPasses", maxNumOrthogPasses);
154 }
catch (InvalidParameterName&) {
159 params->remove (
"depTol");
160 }
catch (InvalidParameterName&) {
163 params->set (
"blkTol", blkTol);
168 }
catch (InvalidParameterName&) {
170 params->set (
"singTol", singTol);
173 max_ortho_steps_ = maxNumOrthogPasses;
177 this->setMyParamList (params);
183 if (defaultParams_.is_null()) {
184 defaultParams_ = Belos::getIMGSDefaultParameters<ScalarType, MV, OP>();
187 return defaultParams_;
332 projectAndNormalizeWithMxImpl (MV &X,
380 void setLabel(
const std::string& label);
384 const std::string&
getLabel()
const {
return label_; }
418 #ifdef BELOS_TEUCHOS_TIME_MONITOR
420 #endif // BELOS_TEUCHOS_TIME_MONITOR
428 bool completeBasis,
int howMany = -1 )
const;
460 template<
class StorageType,
class MV,
class OP>
461 const int IMGSOrthoManager<Sacado::MP::Vector<StorageType>,MV,OP>::max_ortho_steps_default_ = 1;
463 template<
class StorageType,
class MV,
class OP>
464 const typename IMGSOrthoManager<Sacado::MP::Vector<StorageType>,MV,OP>::MagnitudeType
465 IMGSOrthoManager<Sacado::MP::Vector<StorageType>,MV,OP>::blk_tol_default_
469 template<
class StorageType,
class MV,
class OP>
470 const typename IMGSOrthoManager<Sacado::MP::Vector<StorageType>,MV,OP>::MagnitudeType
471 IMGSOrthoManager<Sacado::MP::Vector<StorageType>,MV,OP>::sing_tol_default_
474 template<
class StorageType,
class MV,
class OP>
475 const int IMGSOrthoManager<Sacado::MP::Vector<StorageType>,MV,OP>::max_ortho_steps_fast_ = 1;
477 template<
class StorageType,
class MV,
class OP>
478 const typename IMGSOrthoManager<Sacado::MP::Vector<StorageType>,MV,OP>::MagnitudeType
479 IMGSOrthoManager<Sacado::MP::Vector<StorageType>,MV,OP>::blk_tol_fast_
482 template<
class StorageType,
class MV,
class OP>
483 const typename IMGSOrthoManager<Sacado::MP::Vector<StorageType>,MV,OP>::MagnitudeType
484 IMGSOrthoManager<Sacado::MP::Vector<StorageType>,MV,OP>::sing_tol_fast_
489 template<
class StorageType,
class MV,
class OP>
490 void IMGSOrthoManager<Sacado::MP::Vector<StorageType>,MV,OP>::setLabel(
const std::string& label)
492 if (label != label_) {
494 #ifdef BELOS_TEUCHOS_TIME_MONITOR
495 std::stringstream ss;
496 ss << label_ +
": IMGS[" << max_ortho_steps_ <<
"]";
498 std::string orthoLabel = ss.str() +
": Orthogonalization";
501 std::string updateLabel = ss.str() +
": Ortho (Update)";
504 std::string normLabel = ss.str() +
": Ortho (Norm)";
507 std::string ipLabel = ss.str() +
": Ortho (Inner Product)";
515 template<
class StorageType,
class MV,
class OP>
517 IMGSOrthoManager<Sacado::MP::Vector<StorageType>,MV,OP>::orthonormError(
const MV &X,
Teuchos::RCP<const MV> MX)
const {
518 const ScalarType ONE = SCT::one();
519 int rank = MVT::GetNumberVecs(X);
521 MatOrthoManager<ScalarType,MV,OP>::innerProd(X,X,MX,xTx);
522 for (
int i=0; i<rank; i++) {
525 return xTx.normFrobenius();
530 template<
class StorageType,
class MV,
class OP>
532 IMGSOrthoManager<Sacado::MP::Vector<StorageType>,MV,OP>::orthogError(
const MV &X1,
Teuchos::RCP<const MV> MX1,
const MV &X2)
const {
533 int r1 = MVT::GetNumberVecs(X1);
534 int r2 = MVT::GetNumberVecs(X2);
536 MatOrthoManager<ScalarType,MV,OP>::innerProd(X2,X1,MX1,xTx);
537 return xTx.normFrobenius();
542 template<
class StorageType,
class MV,
class OP>
544 IMGSOrthoManager<Sacado::MP::Vector<StorageType>, MV, OP>::
545 projectAndNormalizeWithMxImpl(MV &X,
557 typedef SerialDenseMatrix< int, ScalarType > serial_dense_matrix_type;
558 typedef typename Array< RCP< const MV > >::size_type size_type;
560 #ifdef BELOS_TEUCHOS_TIME_MONITOR
564 ScalarType ONE = SCT::one();
565 const MagnitudeType ZERO = MGT::zero();
568 int xc = MVT::GetNumberVecs( X );
569 ptrdiff_t xr = MVT::GetGlobalLength( X );
576 B =
rcp (
new serial_dense_matrix_type (xc, xc));
586 for (size_type k = 0; k < nq; ++k)
588 const int numRows = MVT::GetNumberVecs (*Q[k]);
589 const int numCols = xc;
592 C[k] =
rcp (
new serial_dense_matrix_type (numRows, numCols));
593 else if (
C[k]->numRows() != numRows ||
C[k]->numCols() != numCols)
595 int err =
C[k]->reshape (numRows, numCols);
597 "IMGS orthogonalization: failed to reshape "
598 "C[" << k <<
"] (the array of block "
599 "coefficients resulting from projecting X "
600 "against Q[1:" << nq <<
"]).");
608 MX = MVT::Clone(X,MVT::GetNumberVecs(X));
609 OPT::Apply(*(this->_Op),X,*MX);
617 int mxc = MVT::GetNumberVecs( *MX );
618 ptrdiff_t mxr = MVT::GetGlobalLength( *MX );
621 TEUCHOS_TEST_FOR_EXCEPTION( xc == 0 || xr == 0, std::invalid_argument,
"Belos::IMGSOrthoManager::projectAndNormalize(): X must be non-empty" );
624 for (
int i=0; i<nq; i++) {
625 numbas += MVT::GetNumberVecs( *Q[i] );
630 "Belos::IMGSOrthoManager::projectAndNormalize(): Size of X must be consistant with size of B" );
633 "Belos::IMGSOrthoManager::projectAndNormalize(): MVT returned negative dimensions for X,MX" );
636 "Belos::IMGSOrthoManager::projectAndNormalize(): Size of X must be consistant with size of MX" );
642 bool dep_flg =
false;
646 tmpX = MVT::CloneCopy(X);
648 tmpMX = MVT::CloneCopy(*MX);
655 dep_flg = blkOrtho1( X, MX,
C, Q );
661 std::vector<ScalarType>
diag(xc);
663 #ifdef BELOS_TEUCHOS_TIME_MONITOR
666 MVT::MvDot( X, *MX,
diag );
668 (*B)(0,0) = SCT::squareroot(SCT::magnitude(
diag[0]));
670 ScalarType scale = ONE;
675 MVT::MvScale( X, scale );
678 MVT::MvScale( *MX, scale );
684 dep_flg = blkOrtho( X, MX,
C, Q );
690 rank = blkOrthoSing( *tmpX, tmpMX,
C,
B, Q );
693 MVT::Assign( *tmpX, X );
695 MVT::Assign( *tmpMX, *MX );
700 rank = findBasis( X, MX,
B,
false );
705 rank = blkOrthoSing( *tmpX, tmpMX,
C,
B, Q );
708 MVT::Assign( *tmpX, X );
710 MVT::Assign( *tmpMX, *MX );
718 "Belos::IMGSOrthoManager::projectAndNormalize(): Debug error in rank variable." );
728 template<
class StorageType,
class MV,
class OP>
729 int IMGSOrthoManager<Sacado::MP::Vector<StorageType>, MV, OP>::normalize(
733 #ifdef BELOS_TEUCHOS_TIME_MONITOR
738 return findBasis(X, MX,
B,
true);
744 template<
class StorageType,
class MV,
class OP>
745 void IMGSOrthoManager<Sacado::MP::Vector<StorageType>, MV, OP>::project(
764 #ifdef BELOS_TEUCHOS_TIME_MONITOR
768 int xc = MVT::GetNumberVecs( X );
769 ptrdiff_t xr = MVT::GetGlobalLength( X );
771 std::vector<int> qcs(nq);
773 if (nq == 0 || xc == 0 || xr == 0) {
776 ptrdiff_t qr = MVT::GetGlobalLength ( *Q[0] );
787 MX = MVT::Clone(X,MVT::GetNumberVecs(X));
788 OPT::Apply(*(this->_Op),X,*MX);
795 int mxc = MVT::GetNumberVecs( *MX );
796 ptrdiff_t mxr = MVT::GetGlobalLength( *MX );
800 "Belos::IMGSOrthoManager::project(): MVT returned negative dimensions for X,MX" );
803 "Belos::IMGSOrthoManager::project(): Size of X not consistant with MX,Q" );
807 for (
int i=0; i<nq; i++) {
809 "Belos::IMGSOrthoManager::project(): Q lengths not mutually consistant" );
810 qcs[i] = MVT::GetNumberVecs( *Q[i] );
812 "Belos::IMGSOrthoManager::project(): Q has less rows than columns" );
821 "Belos::IMGSOrthoManager::project(): Size of Q not consistant with size of C" );
826 blkOrtho( X, MX,
C, Q );
833 template<
class StorageType,
class MV,
class OP>
834 int IMGSOrthoManager<Sacado::MP::Vector<StorageType>, MV, OP>::findBasis(
837 bool completeBasis,
int howMany )
const {
854 const ScalarType ONE = SCT::one();
855 const MagnitudeType ZERO = SCT::magnitude(SCT::zero());
857 int xc = MVT::GetNumberVecs( X );
858 ptrdiff_t xr = MVT::GetGlobalLength( X );
873 MX = MVT::Clone(X,xc);
874 OPT::Apply(*(this->_Op),X,*MX);
885 int mxc = (this->_hasOp) ? MVT::GetNumberVecs( *MX ) : xc;
886 ptrdiff_t mxr = (this->_hasOp) ? MVT::GetGlobalLength( *MX ) : xr;
890 "Belos::IMGSOrthoManager::findBasis(): X must be non-empty" );
892 "Belos::IMGSOrthoManager::findBasis(): Size of X not consistant with size of B" );
894 "Belos::IMGSOrthoManager::findBasis(): Size of X not consistant with size of MX" );
896 "Belos::IMGSOrthoManager::findBasis(): Size of X not feasible for normalization" );
898 "Belos::IMGSOrthoManager::findBasis(): Invalid howMany parameter" );
903 int xstart = xc - howMany;
905 for (
int j = xstart;
j < xc;
j++) {
914 std::vector<int> index(1);
918 if ((this->_hasOp)) {
920 MXj = MVT::CloneViewNonConst( *MX, index );
929 oldMXj = MVT::CloneCopy( *MXj );
937 std::vector<ScalarType> oldDot( 1 ), newDot( 1 );
942 #ifdef BELOS_TEUCHOS_TIME_MONITOR
945 MVT::MvDot( *Xj, *MXj, oldDot );
949 "Belos::IMGSOrthoManager::findBasis(): Negative definiteness discovered in inner product" );
952 for (
int ii=0; ii<numX; ii++) {
955 prevX = MVT::CloneView( X, index );
957 prevMX = MVT::CloneView( *MX, index );
960 for (
int i=0; i<max_ortho_steps_; ++i) {
964 #ifdef BELOS_TEUCHOS_TIME_MONITOR
967 MatOrthoManager<ScalarType,MV,OP>::innerProd(*prevX,*Xj,MXj,P2);
973 #ifdef BELOS_TEUCHOS_TIME_MONITOR
976 MVT::MvTimesMatAddMv( -ONE, *prevX, P2, ONE, *Xj );
984 #ifdef BELOS_TEUCHOS_TIME_MONITOR
987 MVT::MvTimesMatAddMv( -ONE, *prevMX, P2, ONE, *MXj );
994 product[ii] += P2[0];
1002 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1005 MVT::MvDot( *Xj, *oldMXj, newDot );
1008 newDot[0] = oldDot[0];
1012 if (completeBasis) {
1016 if ( SCT::magnitude(newDot[0]) < SCT::magnitude(sing_tol_*oldDot[0]) ) {
1021 std::cout <<
"Belos::IMGSOrthoManager::findBasis() --> Random for column " << numX << std::endl;
1026 MVT::MvRandom( *tempXj );
1028 tempMXj = MVT::Clone( X, 1 );
1029 OPT::Apply( *(this->_Op), *tempXj, *tempMXj );
1035 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1038 MVT::MvDot( *tempXj, *tempMXj, oldDot );
1042 for (
int ii=0; ii<numX; ii++) {
1045 prevX = MVT::CloneView( X, index );
1047 prevMX = MVT::CloneView( *MX, index );
1050 for (
int num_orth=0; num_orth<max_ortho_steps_; num_orth++){
1052 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1055 MatOrthoManager<ScalarType,MV,OP>::innerProd(*prevX,*tempXj,tempMXj,P2);
1058 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1061 MVT::MvTimesMatAddMv( -ONE, *prevX, P2, ONE, *tempXj );
1064 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1067 MVT::MvTimesMatAddMv( -ONE, *prevMX, P2, ONE, *tempMXj );
1072 product[ii] = P2[0];
1074 product[ii] += P2[0];
1080 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1083 MVT::MvDot( *tempXj, *tempMXj, newDot );
1086 if ( SCT::magnitude(newDot[0]) >= SCT::magnitude(oldDot[0]*sing_tol_) ) {
1088 MVT::Assign( *tempXj, *Xj );
1090 MVT::Assign( *tempMXj, *MXj );
1102 if ( SCT::magnitude(newDot[0]) < SCT::magnitude(oldDot[0]*blk_tol_) ) {
1111 ScalarType
diag = SCT::squareroot(SCT::magnitude(newDot[0]));
1112 ScalarType scale = ONE;
1114 MVT::MvScale( *Xj, scale );
1117 MVT::MvScale( *MXj, scale );
1130 for (
int i=0; i<numX; i++) {
1131 (*B)(i,
j) = product(i);
1142 template<
class StorageType,
class MV,
class OP>
1144 IMGSOrthoManager<Sacado::MP::Vector<StorageType>, MV, OP>::blkOrtho1 ( MV &X,
Teuchos::RCP<MV> MX,
1149 int xc = MVT::GetNumberVecs( X );
1150 const ScalarType ONE = SCT::one();
1152 std::vector<int> qcs( nq );
1153 for (
int i=0; i<nq; i++) {
1154 qcs[i] = MVT::GetNumberVecs( *Q[i] );
1158 std::vector<int> index(1);
1163 for (
int i=0; i<nq; i++) {
1166 for (
int ii=0; ii<qcs[i]; ii++) {
1169 tempQ = MVT::CloneView( *Q[i], index );
1174 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1177 MatOrthoManager<ScalarType,MV,OP>::innerProd(*tempQ,X,MX,tempC);
1181 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1184 MVT::MvTimesMatAddMv( -ONE, *tempQ, tempC, ONE, X );
1191 OPT::Apply( *(this->_Op), X, *MX);
1195 MQ[i] = MVT::Clone( *Q[i], qcs[i] );
1196 OPT::Apply( *(this->_Op), *Q[i], *MQ[i] );
1197 MVT::MvTimesMatAddMv( -ONE, *MQ[i], *
C[i], ONE, *MX );
1203 for (
int j = 1;
j < max_ortho_steps_; ++
j) {
1205 for (
int i=0; i<nq; i++) {
1210 for (
int ii=0; ii<qcs[i]; ii++) {
1213 tempQ = MVT::CloneView( *Q[i], index );
1219 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1222 MatOrthoManager<ScalarType,MV,OP>::innerProd( *tempQ, X, MX, tempC2 );
1226 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1229 MVT::MvTimesMatAddMv( -ONE, *tempQ, tempC2, ONE, X );
1238 MVT::MvTimesMatAddMv( -ONE, *MQ[i], C2, ONE, *MX );
1240 else if (xc <= qcs[i]) {
1242 OPT::Apply( *(this->_Op), X, *MX);
1253 template<
class StorageType,
class MV,
class OP>
1255 IMGSOrthoManager<Sacado::MP::Vector<StorageType>, MV, OP>::blkOrtho ( MV &X,
Teuchos::RCP<MV> MX,
1260 int xc = MVT::GetNumberVecs( X );
1261 bool dep_flg =
false;
1262 const ScalarType ONE = SCT::one();
1264 std::vector<int> qcs( nq );
1265 for (
int i=0; i<nq; i++) {
1266 qcs[i] = MVT::GetNumberVecs( *Q[i] );
1272 std::vector<ScalarType> oldDot( xc );
1274 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1277 MVT::MvDot( X, *MX, oldDot );
1280 std::vector<int> index(1);
1285 for (
int i=0; i<nq; i++) {
1288 for (
int ii=0; ii<qcs[i]; ii++) {
1291 tempQ = MVT::CloneView( *Q[i], index );
1296 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1299 MatOrthoManager<ScalarType,MV,OP>::innerProd( *tempQ, X, MX, tempC);
1303 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1306 MVT::MvTimesMatAddMv( -ONE, *tempQ, tempC, ONE, X );
1313 OPT::Apply( *(this->_Op), X, *MX);
1317 MQ[i] = MVT::Clone( *Q[i], qcs[i] );
1318 OPT::Apply( *(this->_Op), *Q[i], *MQ[i] );
1319 MVT::MvTimesMatAddMv( -ONE, *MQ[i], *
C[i], ONE, *MX );
1325 for (
int j = 1;
j < max_ortho_steps_; ++
j) {
1327 for (
int i=0; i<nq; i++) {
1331 for (
int ii=0; ii<qcs[i]; ii++) {
1334 tempQ = MVT::CloneView( *Q[i], index );
1340 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1343 MatOrthoManager<ScalarType,MV,OP>::innerProd( *tempQ, X, MX, tempC2 );
1347 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1350 MVT::MvTimesMatAddMv( -ONE, *tempQ, tempC2, ONE, X );
1358 MVT::MvTimesMatAddMv( -ONE, *MQ[i], C2, ONE, *MX );
1360 else if (xc <= qcs[i]) {
1362 OPT::Apply( *(this->_Op), X, *MX);
1369 std::vector<ScalarType> newDot(xc);
1371 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1374 MVT::MvDot( X, *MX, newDot );
1378 for (
int i=0; i<xc; i++){
1379 if (SCT::magnitude(newDot[i]) < SCT::magnitude(oldDot[i] * blk_tol_)) {
1388 template<
class StorageType,
class MV,
class OP>
1390 IMGSOrthoManager<Sacado::MP::Vector<StorageType>, MV, OP>::blkOrthoSing ( MV &X,
Teuchos::RCP<MV> MX,
1397 const ScalarType ONE = SCT::one();
1398 const ScalarType ZERO = SCT::zero();
1401 int xc = MVT::GetNumberVecs( X );
1402 std::vector<int> indX( 1 );
1403 std::vector<ScalarType> oldDot( 1 ), newDot( 1 );
1405 std::vector<int> qcs( nq );
1406 for (
int i=0; i<nq; i++) {
1407 qcs[i] = MVT::GetNumberVecs( *Q[i] );
1416 for (
int j=0;
j<xc;
j++) {
1418 bool dep_flg =
false;
1422 std::vector<int> index(
j );
1423 for (
int ind=0; ind<
j; ind++) {
1426 lastQ = MVT::CloneView( X, index );
1429 Q.push_back( lastQ );
1431 qcs.push_back( MVT::GetNumberVecs( *lastQ ) );
1436 Xj = MVT::CloneViewNonConst( X, indX );
1438 MXj = MVT::CloneViewNonConst( *MX, indX );
1446 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1449 MVT::MvDot( *Xj, *MXj, oldDot );
1456 for (
int i=0; i<Q.size(); i++) {
1459 for (
int ii=0; ii<qcs[i]; ii++) {
1462 tempQ = MVT::CloneView( *Q[i], indX );
1467 MatOrthoManager<ScalarType,MV,OP>::innerProd(*tempQ,*Xj,MXj,tempC);
1470 MVT::MvTimesMatAddMv( -ONE, *tempQ, tempC, ONE, *Xj );
1476 OPT::Apply( *(this->_Op), *Xj, *MXj);
1480 MQ[i] = MVT::Clone( *Q[i], qcs[i] );
1481 OPT::Apply( *(this->_Op), *Q[i], *MQ[i] );
1483 MVT::MvTimesMatAddMv( -ONE, *MQ[i], tempC, ONE, *MXj );
1489 for (
int num_ortho_steps=1; num_ortho_steps < max_ortho_steps_; ++num_ortho_steps) {
1491 for (
int i=0; i<Q.size(); i++) {
1495 for (
int ii=0; ii<qcs[i]; ii++) {
1498 tempQ = MVT::CloneView( *Q[i], indX );
1503 MatOrthoManager<ScalarType,MV,OP>::innerProd( *tempQ, *Xj, MXj, tempC2);
1504 MVT::MvTimesMatAddMv( -ONE, *tempQ, tempC2, ONE, *Xj );
1515 MVT::MvTimesMatAddMv( -ONE, *MQ[i], C2, ONE, *MXj );
1517 else if (xc <= qcs[i]) {
1519 OPT::Apply( *(this->_Op), *Xj, *MXj);
1527 if (SCT::magnitude(newDot[0]) < SCT::magnitude(oldDot[0]*sing_tol_)) {
1533 ScalarType diag = SCT::squareroot(SCT::magnitude(newDot[0]));
1535 MVT::MvScale( *Xj, ONE/diag );
1538 MVT::MvScale( *MXj, ONE/diag );
1548 MVT::MvRandom( *tempXj );
1550 tempMXj = MVT::Clone( X, 1 );
1551 OPT::Apply( *(this->_Op), *tempXj, *tempMXj );
1557 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1560 MVT::MvDot( *tempXj, *tempMXj, oldDot );
1563 for (
int num_orth=0; num_orth<max_ortho_steps_; num_orth++) {
1565 for (
int i=0; i<Q.size(); i++) {
1569 for (
int ii=0; ii<qcs[i]; ii++) {
1572 tempQ = MVT::CloneView( *Q[i], indX );
1576 MatOrthoManager<ScalarType,MV,OP>::innerProd( *tempQ, *tempXj, tempMXj, tempC );
1577 MVT::MvTimesMatAddMv( -ONE, *tempQ, tempC, ONE, *tempXj );
1585 MVT::MvTimesMatAddMv( -ONE, *MQ[i], product, ONE, *tempMXj );
1587 else if (xc <= qcs[i]) {
1589 OPT::Apply( *(this->_Op), *tempXj, *tempMXj);
1597 #ifdef BELOS_TEUCHOS_TIME_MONITOR
1600 MVT::MvDot( *tempXj, *tempMXj, newDot );
1604 if ( SCT::magnitude(newDot[0]) >= SCT::magnitude(oldDot[0]*sing_tol_) ) {
1605 ScalarType diag = SCT::squareroot(SCT::magnitude(newDot[0]));
1611 MVT::MvAddMv( ONE/diag, *tempXj, ZERO, *tempXj, *Xj );
1613 MVT::MvAddMv( ONE/diag, *tempMXj, ZERO, *tempMXj, *MXj );
1635 #endif // BELOS_IMGS_ORTHOMANAGER_HPP
void project(MV &X, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
This method calls project(X,Teuchos::null,C,Q); see documentation for that function.
bool is_null(const boost::shared_ptr< T > &p)
Teuchos::ScalarTraits< ScalarType >::magnitudeType orthogError(const MV &X1, const MV &X2) const
This method computes the error in orthogonality of two multivectors, measured as the Frobenius norm o...
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &plist)
OperatorTraits< ScalarType, MV, OP > OPT
MagnitudeType sing_tol_
Singular block detection threshold.
T & get(ParameterList &l, const std::string &name)
bool is_null(const std::shared_ptr< T > &p)
const std::string & getLabel() const
This method returns the label being used by the timers in the orthogonalization manager.
static const int max_ortho_steps_fast_
Max number of (re)orthogonalization steps, including the first (fast).
void setSingTol(const MagnitudeType sing_tol)
Set parameter for singular block detection.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::ScalarTraits< ScalarType > SCT
Teuchos::ScalarTraits< ScalarType >::magnitudeType orthonormError(const MV &X) const
This method computes the error in orthonormality of a multivector, measured as the Frobenius norm of ...
static const MagnitudeType sing_tol_fast_
Singular block detection threshold (fast).
int normalize(MV &X, Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B) const
This method calls normalize(X,Teuchos::null,B); see documentation for that function.
IMGSOrthoManager(const Teuchos::RCP< Teuchos::ParameterList > &plist, const std::string &label="Belos", Teuchos::RCP< const OP > Op=Teuchos::null)
Constructor that takes a list of parameters.
KOKKOS_INLINE_FUNCTION bool OR(Mask< T > m)
Teuchos::ScalarTraits< ScalarType >::magnitudeType MagnitudeType
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
KOKKOS_INLINE_FUNCTION MaskedAssign< scalar > mask_assign(bool b, scalar *s)
int max_ortho_steps_
Max number of (re)orthogonalization steps, including the first.
Sacado::MP::Vector< Storage > ScalarType
IMGSOrthoManager(const std::string &label="Belos", Teuchos::RCP< const OP > Op=Teuchos::null, const int max_ortho_steps=max_ortho_steps_default_, const MagnitudeType blk_tol=blk_tol_default_, const MagnitudeType sing_tol=sing_tol_default_)
Constructor specifying re-orthogonalization tolerance.
static const MagnitudeType blk_tol_fast_
Block reorthogonalization threshold (fast).
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void setBlkTol(const MagnitudeType blk_tol)
Set parameter for block re-orthogonalization threshhold.
bool is_null(const RCP< T > &p)
MultiVecTraits< ScalarType, MV > MVT
static const MagnitudeType sing_tol_default_
Singular block detection threshold (default).
Teuchos::RCP< Teuchos::ParameterList > defaultParams_
Default parameter list.
~IMGSOrthoManager()
Destructor.
static const int max_ortho_steps_default_
Max number of (re)orthogonalization steps, including the first (default).
MagnitudeType getSingTol() const
Return parameter for singular block detection.
static const MagnitudeType blk_tol_default_
Block reorthogonalization threshold (default).
std::string label_
Label for timers.
MagnitudeType blk_tol_
Block reorthogonalization tolerance.
Teuchos::ScalarTraits< MagnitudeType > MGT
MagnitudeType getBlkTol() const
Return parameter for block re-orthogonalization threshhold.