| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// ShyLU: Scalable Hybrid LU Preconditioner and Solver |
| 4 |
// |
| 5 |
// Copyright 2011 NTESS and the ShyLU contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
/** \file Ifpack_ShyLU.h |
| 11 |
|
| 12 |
\brief Use ShyLU as a preconditioner within IFPACK. |
| 13 |
|
| 14 |
\author Siva Rajamanickam |
| 15 |
|
| 16 |
*/ |
| 17 |
|
| 18 |
#ifndef IFPACK_SHYLU_H |
| 19 |
#define IFPACK_SHYLU_H |
| 20 |
|
| 21 |
#if defined(ShyLU_DDCore_SHOW_DEPRECATED_WARNINGS) |
| 22 |
#ifdef __GNUC__ |
| 23 |
#warning "The ShyLU_DDCore package is deprecated" |
| 24 |
#endif |
| 25 |
#endif |
| 26 |
|
| 27 |
#include <assert.h> |
| 28 |
#include <iostream> |
| 29 |
#include <sstream> |
| 30 |
#include <string> |
| 31 |
|
| 32 |
/* This define will make S block diagonal, To make this happen even some |
| 33 |
zero columns/rows of C and R will be stored. |
| 34 |
*/ |
| 35 |
#define BLOCK_DIAGONAL_Si |
| 36 |
|
| 37 |
#include "ShyLU_DDCore_config.h" |
| 38 |
|
| 39 |
// Epetra includes |
| 40 |
#ifdef HAVE_SHYLU_DDCORE_MPI |
| 41 |
#include "Epetra_MpiComm.h" |
| 42 |
#else |
| 43 |
#include "Epetra_SerialComm.h" |
| 44 |
#endif |
| 45 |
#include "Epetra_SerialComm.h" |
| 46 |
#include "Epetra_Time.h" |
| 47 |
#include "Epetra_CrsMatrix.h" |
| 48 |
#include "Epetra_Map.h" |
| 49 |
#include "Epetra_MultiVector.h" |
| 50 |
#include "Epetra_LinearProblem.h" |
| 51 |
#include "Epetra_Import.h" |
| 52 |
#include "Epetra_Export.h" |
| 53 |
|
| 54 |
// Teuchos includes |
| 55 |
#include "Teuchos_GlobalMPISession.hpp" |
| 56 |
#include "Teuchos_XMLParameterListHelpers.hpp" |
| 57 |
#include "Teuchos_LAPACK.hpp" |
| 58 |
|
| 59 |
// AztecOO includes |
| 60 |
#include "AztecOO.h" |
| 61 |
|
| 62 |
#include "shylu.h" |
| 63 |
#include "shylu_util.h" |
| 64 |
|
| 65 |
// Ifpack includes |
| 66 |
#include "Ifpack_Preconditioner.h" |
| 67 |
|
| 68 |
//Isorropia includes |
| 69 |
#include "Isorropia_Epetra.hpp" |
| 70 |
#include "Isorropia_EpetraRedistributor.hpp" |
| 71 |
#include "Isorropia_EpetraPartitioner.hpp" |
| 72 |
|
| 73 |
// EpetraExt includes |
| 74 |
#include "EpetraExt_MultiVectorOut.h" |
| 75 |
#include "EpetraExt_RowMatrixOut.h" |
| 76 |
|
| 77 |
// Amesos includes |
| 78 |
#include "Amesos.h" |
| 79 |
#include "Amesos_BaseSolver.h" |
| 80 |
|
| 81 |
/** \brief ShyLU's interface to be used as an Ifpack Preconditioner |
| 82 |
* |
| 83 |
*/ |
| 84 |
class Ifpack_ShyLU: public Ifpack_Preconditioner |
| 85 |
{ |
| 86 |
public: |
| 87 |
// @{ Constructors and destructors. |
| 88 |
//! Constructor |
| 89 |
Ifpack_ShyLU(Epetra_CrsMatrix* A); |
| 90 |
|
| 91 |
//! Destructor |
| 92 |
~Ifpack_ShyLU() |
| 93 |
{ |
| 94 |
Destroy(); |
| 95 |
} |
| 96 |
|
| 97 |
// @} |
| 98 |
// @{ Construction methods |
| 99 |
|
| 100 |
//! Initialize the preconditioner, does not touch matrix values. |
| 101 |
int Initialize(); |
| 102 |
|
| 103 |
//! Returns \c true if the preconditioner has been successfully initialized. |
| 104 |
bool IsInitialized() const |
| 105 |
{ |
| 106 |
return(IsInitialized_); |
| 107 |
} |
| 108 |
|
| 109 |
//! Compute ILU factors L and U using the specified parameters. |
| 110 |
int Compute(); |
| 111 |
|
| 112 |
//! If factor is completed, this query returns true, otherwise it returns false. |
| 113 |
bool IsComputed() const |
| 114 |
{ |
| 115 |
return(IsComputed_); |
| 116 |
} |
| 117 |
|
| 118 |
//! Set parameters using a Teuchos::ParameterList object. |
| 119 |
/* This method is only available if the Teuchos package is enabled. |
| 120 |
This method recognizes four parameter names: relax_value, |
| 121 |
absolute_threshold, relative_threshold and overlap_mode. These names are |
| 122 |
case insensitive, and in each case except overlap_mode, the ParameterEntry |
| 123 |
must have type double. For overlap_mode, the ParameterEntry must have |
| 124 |
type Epetra_CombineMode. |
| 125 |
*/ |
| 126 |
int SetParameters(Teuchos::ParameterList& parameterlist); |
| 127 |
|
| 128 |
int SetUseTranspose(bool UseTranspose_in) { |
| 129 |
UseTranspose_ = UseTranspose_in; |
| 130 |
return(0); |
| 131 |
}; |
| 132 |
|
| 133 |
//! Returns the current UseTranspose setting. |
| 134 |
bool UseTranspose() const {return(UseTranspose_);}; |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
// @} |
| 140 |
|
| 141 |
// @{ Mathematical functions. |
| 142 |
// Applies the matrix to X, returns the result in Y. |
| 143 |
int Apply(const Epetra_MultiVector& X, |
| 144 |
Epetra_MultiVector& Y) const |
| 145 |
{ |
| 146 |
return(Multiply(false,X,Y)); |
| 147 |
} |
| 148 |
|
| 149 |
int Multiply(bool Trans, const Epetra_MultiVector& X, |
| 150 |
Epetra_MultiVector& Y) const{return A_->Multiply(Trans,X,Y);} |
| 151 |
|
| 152 |
//! Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y. |
| 153 |
/*! |
| 154 |
\param |
| 155 |
X - (In) A Epetra_MultiVector of dimension NumVectors to solve for. |
| 156 |
\param Out |
| 157 |
Y - (Out) A Epetra_MultiVector of dimension NumVectors containing result. |
| 158 |
|
| 159 |
\return Integer error code, set to 0 if successful. |
| 160 |
*/ |
| 161 |
int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const; |
| 162 |
|
| 163 |
//! Computes the estimated condition number and returns the value. |
| 164 |
double Condest(const Ifpack_CondestType CT = Ifpack_Cheap, |
| 165 |
const int MaxIters = 1550, |
| 166 |
const double Tol = 1e-9, |
| 167 |
Epetra_RowMatrix* Matrix_in = 0); |
| 168 |
|
| 169 |
//! Returns the computed estimated condition number, or -1.0 if not computed. |
| 170 |
int JustTryIt() ; |
| 171 |
|
| 172 |
double Condest() const |
| 173 |
{ |
| 174 |
return(Condest_); |
| 175 |
} |
| 176 |
|
| 177 |
// @} |
| 178 |
// @{ Query methods |
| 179 |
|
| 180 |
//! Returns a character string describing the operator |
| 181 |
const char* Label() const {return(Label_.c_str());} |
| 182 |
|
| 183 |
//! Sets label for \c this object. |
| 184 |
int SetLabel(std::string Label_in) |
| 185 |
{ |
| 186 |
Label_ = Label_in; |
| 187 |
return(0); |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
//! Returns 0.0 because this class cannot compute Inf-norm. |
| 192 |
double NormInf() const {return(0.0);}; |
| 193 |
|
| 194 |
//! Returns false because this class cannot compute an Inf-norm. |
| 195 |
bool HasNormInf() const {return(false);}; |
| 196 |
|
| 197 |
//! Returns the Epetra_Map object associated with the domain of this operator. |
| 198 |
const Epetra_Map & OperatorDomainMap() const {return(A_->OperatorDomainMap());}; |
| 199 |
|
| 200 |
//! Returns the Epetra_Map object associated with the range of this operator. |
| 201 |
const Epetra_Map & OperatorRangeMap() const{return(A_->OperatorRangeMap());}; |
| 202 |
|
| 203 |
//! Returns the Epetra_BlockMap object associated with the range of this matrix operator. |
| 204 |
const Epetra_Comm & Comm() const{return(A_->Comm());}; |
| 205 |
|
| 206 |
//! Returns a reference to the matrix to be preconditioned. |
| 207 |
const Epetra_RowMatrix& Matrix() const |
| 208 |
{ |
| 209 |
return(*A_); |
| 210 |
} |
| 211 |
|
| 212 |
//! Prints on stream basic information about \c this object. |
| 213 |
virtual std::ostream& Print(std::ostream& os) const; |
| 214 |
|
| 215 |
//! Returns the number of calls to Initialize(). |
| 216 |
virtual int NumInitialize() const |
| 217 |
{ |
| 218 |
return(NumInitialize_); |
| 219 |
} |
| 220 |
|
| 221 |
//! Returns the number of calls to Compute(). |
| 222 |
virtual int NumCompute() const |
| 223 |
{ |
| 224 |
return(NumCompute_); |
| 225 |
} |
| 226 |
|
| 227 |
//! Returns the number of calls to ApplyInverse(). |
| 228 |
virtual int NumApplyInverse() const |
| 229 |
{ |
| 230 |
return(NumApplyInverse_); |
| 231 |
} |
| 232 |
|
| 233 |
//! Returns the time spent in Initialize(). |
| 234 |
virtual double InitializeTime() const |
| 235 |
{ |
| 236 |
return(InitializeTime_); |
| 237 |
} |
| 238 |
|
| 239 |
//! Returns the time spent in Compute(). |
| 240 |
virtual double ComputeTime() const |
| 241 |
{ |
| 242 |
return(ComputeTime_); |
| 243 |
} |
| 244 |
|
| 245 |
//! Returns the time spent in ApplyInverse(). |
| 246 |
virtual double ApplyInverseTime() const |
| 247 |
{ |
| 248 |
return(ApplyInverseTime_); |
| 249 |
} |
| 250 |
|
| 251 |
//! Returns the number of flops in the initialization phase. |
| 252 |
virtual double InitializeFlops() const |
| 253 |
{ |
| 254 |
return(0.0); |
| 255 |
} |
| 256 |
|
| 257 |
virtual double ComputeFlops() const |
| 258 |
{ |
| 259 |
return(ComputeFlops_); |
| 260 |
} |
| 261 |
|
| 262 |
virtual double ApplyInverseFlops() const |
| 263 |
{ |
| 264 |
return(ApplyInverseFlops_); |
| 265 |
} |
| 266 |
|
| 267 |
private: |
| 268 |
|
| 269 |
// @} |
| 270 |
// @{ Private methods |
| 271 |
|
| 272 |
//! Copy constructor (should never be used) |
| 273 |
Ifpack_ShyLU(const Ifpack_ShyLU& RHS) : |
| 274 |
Time_(RHS.Comm()) |
| 275 |
{} |
| 276 |
|
| 277 |
//! operator= (should never be used) |
| 278 |
Ifpack_ShyLU& operator=(const Ifpack_ShyLU& RHS) |
| 279 |
{ |
| 280 |
return(*this); |
| 281 |
} |
| 282 |
|
| 283 |
//! Destroys all internal data |
| 284 |
void Destroy(); |
| 285 |
|
| 286 |
//! Returns the number of global matrix rows. |
| 287 |
int NumGlobalRows() const {return(A_->NumGlobalRows());}; |
| 288 |
|
| 289 |
//! Returns the number of global matrix columns. |
| 290 |
int NumGlobalCols() const {return(A_->NumGlobalCols());}; |
| 291 |
|
| 292 |
//! Returns the number of local matrix rows. |
| 293 |
int NumMyRows() const {return(A_->NumMyRows());}; |
| 294 |
|
| 295 |
//! Returns the number of local matrix columns. |
| 296 |
int NumMyCols() const {return(A_->NumMyCols());}; |
| 297 |
|
| 298 |
// @} |
| 299 |
// @{ Internal data |
| 300 |
|
| 301 |
//! Pointer to the Epetra_RowMatrix to factorize |
| 302 |
Epetra_CrsMatrix *A_; |
| 303 |
|
| 304 |
Teuchos::ParameterList List_; |
| 305 |
//mutable AztecOO *solver_; // Ugh !!! Mutable ! To workaround AztecOO bug |
| 306 |
mutable shylu_data slu_data_; // More mutable !!! |
| 307 |
mutable shylu_config slu_config_; // More mutable !! |
| 308 |
mutable shylu_symbolic slu_sym_; // More mutable !! |
| 309 |
|
| 310 |
//fpr later use |
| 311 |
// Isorropia::Epetra::Partitioner *partitioner_; // unused |
| 312 |
// Isorropia::Epetra::Redistributor *rd_; // unused |
| 313 |
|
| 314 |
bool UseTranspose_; |
| 315 |
|
| 316 |
double Condest_; |
| 317 |
|
| 318 |
bool IsParallel_; |
| 319 |
//! If \c true, the preconditioner has been successfully initialized. |
| 320 |
bool IsInitialized_; |
| 321 |
//! If \c true, the preconditioner has been successfully computed. |
| 322 |
bool IsComputed_; |
| 323 |
//! Label of \c this object. |
| 324 |
std::string Label_; |
| 325 |
//! Contains the number of successful calls to Initialize(). |
| 326 |
int NumInitialize_; |
| 327 |
//! Contains the number of successful call to Compute(). |
| 328 |
int NumCompute_; |
| 329 |
|
| 330 |
//! Contains the number of successful call to ApplyInverse(). |
| 331 |
mutable int NumApplyInverse_; |
| 332 |
//! Contains the time for all successful calls to Initialize(). |
| 333 |
double InitializeTime_; |
| 334 |
//! Contains the time for all successful calls to Compute(). |
| 335 |
double ComputeTime_; |
| 336 |
//! Contains the time for all successful calls to ApplyInverse(). |
| 337 |
mutable double ApplyInverseTime_; |
| 338 |
//! Contains the number of flops for Compute(). |
| 339 |
double ComputeFlops_; |
| 340 |
//! Contain sthe number of flops for ApplyInverse(). |
| 341 |
mutable double ApplyInverseFlops_; |
| 342 |
//! Used for timing issues |
| 343 |
mutable Epetra_Time Time_; |
| 344 |
// @} |
| 345 |
|
| 346 |
}; |
| 347 |
|
| 348 |
#endif /* IFPACK_SHYLU_H */ |