ShyLU  Version of the Day
Ifpack_ShyLU.h
Go to the documentation of this file.
1 
2 //@HEADER
3 // ************************************************************************
4 //
5 // ShyLU: Hybrid preconditioner package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 
51 #ifndef IFPACK_SHYLU_H
52 #define IFPACK_SHYLU_H
53 
54 #include <assert.h>
55 #include <iostream>
56 #include <sstream>
57 #include <string>
58 
59 /* This define will make S block diagonal, To make this happen even some
60  zero columns/rows of C and R will be stored.
61  */
62 #define BLOCK_DIAGONAL_Si
63 
64 #include "ShyLUCore_config.h"
65 
66 // Epetra includes
67 #ifdef HAVE_SHYLUCORE_MPI
68 #include "Epetra_MpiComm.h"
69 #else
70 #include "Epetra_SerialComm.h"
71 #endif
72 #include "Epetra_SerialComm.h"
73 #include "Epetra_Time.h"
74 #include "Epetra_CrsMatrix.h"
75 #include "Epetra_Map.h"
76 #include "Epetra_MultiVector.h"
77 #include "Epetra_LinearProblem.h"
78 #include "Epetra_Import.h"
79 #include "Epetra_Export.h"
80 
81 // Teuchos includes
84 #include "Teuchos_LAPACK.hpp"
85 
86 // AztecOO includes
87 #include "AztecOO.h"
88 
89 #include "shylu.h"
90 #include "shylu_util.h"
91 
92 // Ifpack includes
93 #include "Ifpack_Preconditioner.h"
94 
95 //Isorropia includes
96 #include "Isorropia_Epetra.hpp"
97 #include "Isorropia_EpetraRedistributor.hpp"
98 #include "Isorropia_EpetraPartitioner.hpp"
99 
100 // EpetraExt includes
101 #include "EpetraExt_MultiVectorOut.h"
102 #include "EpetraExt_RowMatrixOut.h"
103 
104 // Amesos includes
105 #include "Amesos.h"
106 #include "Amesos_BaseSolver.h"
107 
108 using namespace std;
109 
113 class Ifpack_ShyLU: public Ifpack_Preconditioner
114 {
115  public:
116  // @{ Constructors and destructors.
118  Ifpack_ShyLU(Epetra_CrsMatrix* A);
119 
122  {
123  Destroy();
124  }
125 
126  // @}
127  // @{ Construction methods
128 
130  int Initialize();
131 
133  bool IsInitialized() const
134  {
135  return(IsInitialized_);
136  }
137 
139  int Compute();
140 
142  bool IsComputed() const
143  {
144  return(IsComputed_);
145  }
146 
148  /* This method is only available if the Teuchos package is enabled.
149  This method recognizes four parameter names: relax_value,
150  absolute_threshold, relative_threshold and overlap_mode. These names are
151  case insensitive, and in each case except overlap_mode, the ParameterEntry
152  must have type double. For overlap_mode, the ParameterEntry must have
153  type Epetra_CombineMode.
154  */
155  int SetParameters(Teuchos::ParameterList& parameterlist);
156 
157  int SetUseTranspose(bool UseTranspose_in) {
158  UseTranspose_ = UseTranspose_in;
159  return(0);
160  };
161 
163  bool UseTranspose() const {return(UseTranspose_);};
164 
165 
166 
167 
168  // @}
169 
170  // @{ Mathematical functions.
171  // Applies the matrix to X, returns the result in Y.
172  int Apply(const Epetra_MultiVector& X,
173  Epetra_MultiVector& Y) const
174  {
175  return(Multiply(false,X,Y));
176  }
177 
178  int Multiply(bool Trans, const Epetra_MultiVector& X,
179  Epetra_MultiVector& Y) const{return A_->Multiply(Trans,X,Y);}
180 
182 
190  int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
191 
193  double Condest(const Ifpack_CondestType CT = Ifpack_Cheap,
194  const int MaxIters = 1550,
195  const double Tol = 1e-9,
196  Epetra_RowMatrix* Matrix_in = 0);
197 
199 int JustTryIt() ;
200 
201  double Condest() const
202  {
203  return(Condest_);
204  }
205 
206  // @}
207  // @{ Query methods
208 
210  const char* Label() const {return(Label_.c_str());}
211 
213  int SetLabel(std::string Label_in)
214  {
215  Label_ = Label_in;
216  return(0);
217  }
218 
219 
221  double NormInf() const {return(0.0);};
222 
224  bool HasNormInf() const {return(false);};
225 
227  const Epetra_Map & OperatorDomainMap() const {return(A_->OperatorDomainMap());};
228 
230  const Epetra_Map & OperatorRangeMap() const{return(A_->OperatorRangeMap());};
231 
233  const Epetra_Comm & Comm() const{return(A_->Comm());};
234 
236  const Epetra_RowMatrix& Matrix() const
237  {
238  return(*A_);
239  }
240 
242  virtual ostream& Print(ostream& os) const;
243 
245  virtual int NumInitialize() const
246  {
247  return(NumInitialize_);
248  }
249 
251  virtual int NumCompute() const
252  {
253  return(NumCompute_);
254  }
255 
257  virtual int NumApplyInverse() const
258  {
259  return(NumApplyInverse_);
260  }
261 
263  virtual double InitializeTime() const
264  {
265  return(InitializeTime_);
266  }
267 
269  virtual double ComputeTime() const
270  {
271  return(ComputeTime_);
272  }
273 
275  virtual double ApplyInverseTime() const
276  {
277  return(ApplyInverseTime_);
278  }
279 
281  virtual double InitializeFlops() const
282  {
283  return(0.0);
284  }
285 
286  virtual double ComputeFlops() const
287  {
288  return(ComputeFlops_);
289  }
290 
291  virtual double ApplyInverseFlops() const
292  {
293  return(ApplyInverseFlops_);
294  }
295 
296  private:
297 
298  // @}
299  // @{ Private methods
300 
302  Ifpack_ShyLU(const Ifpack_ShyLU& RHS) :
303  Time_(RHS.Comm())
304  {}
305 
307  Ifpack_ShyLU& operator=(const Ifpack_ShyLU& RHS)
308  {
309  return(*this);
310  }
311 
313  void Destroy();
314 
316  int NumGlobalRows() const {return(A_->NumGlobalRows());};
317 
319  int NumGlobalCols() const {return(A_->NumGlobalCols());};
320 
322  int NumMyRows() const {return(A_->NumMyRows());};
323 
325  int NumMyCols() const {return(A_->NumMyCols());};
326 
327  // @}
328  // @{ Internal data
329 
331  Epetra_CrsMatrix *A_;
332 
334  //mutable AztecOO *solver_; // Ugh !!! Mutable ! To workaround AztecOO bug
335  mutable shylu_data slu_data_; // More mutable !!!
336  mutable shylu_config slu_config_; // More mutable !!
337  mutable shylu_symbolic slu_sym_; // More mutable !!
338 
339  //fpr later use
340  // Isorropia::Epetra::Partitioner *partitioner_; // unused
341  // Isorropia::Epetra::Redistributor *rd_; // unused
342 
343  bool UseTranspose_;
344 
345  double Condest_;
346 
347  bool IsParallel_;
349  bool IsInitialized_;
351  bool IsComputed_;
353  std::string Label_;
355  int NumInitialize_;
357  int NumCompute_;
358 
360  mutable int NumApplyInverse_;
362  double InitializeTime_;
364  double ComputeTime_;
366  mutable double ApplyInverseTime_;
368  double ComputeFlops_;
370  mutable double ApplyInverseFlops_;
372  mutable Epetra_Time Time_;
373  // @}
374 
375 };
376 
377 #endif /* IFPACK_SHYLU_H */
const Epetra_RowMatrix & Matrix() const
Returns a reference to the matrix to be preconditioned.
Definition: Ifpack_ShyLU.h:236
double NormInf() const
Returns 0.0 because this class cannot compute Inf-norm.
Definition: Ifpack_ShyLU.h:221
~Ifpack_ShyLU()
Destructor.
Definition: Ifpack_ShyLU.h:121
ShyLU&#39;s interface to be used as an Ifpack Preconditioner.
Definition: Ifpack_ShyLU.h:113
const Epetra_Comm & Comm() const
Returns the Epetra_BlockMap object associated with the range of this matrix operator.
Definition: Ifpack_ShyLU.h:233
virtual double ComputeTime() const
Returns the time spent in Compute().
Definition: Ifpack_ShyLU.h:269
virtual int NumApplyInverse() const
Returns the number of calls to ApplyInverse().
Definition: Ifpack_ShyLU.h:257
bool UseTranspose() const
Returns the current UseTranspose setting.
Definition: Ifpack_ShyLU.h:163
bool HasNormInf() const
Returns false because this class cannot compute an Inf-norm.
Definition: Ifpack_ShyLU.h:224
virtual int NumInitialize() const
Returns the number of calls to Initialize().
Definition: Ifpack_ShyLU.h:245
bool IsInitialized() const
Returns true if the preconditioner has been successfully initialized.
Definition: Ifpack_ShyLU.h:133
virtual double ApplyInverseTime() const
Returns the time spent in ApplyInverse().
Definition: Ifpack_ShyLU.h:275
const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
Definition: Ifpack_ShyLU.h:227
const char * Label() const
Returns a character string describing the operator.
Definition: Ifpack_ShyLU.h:210
virtual double InitializeTime() const
Returns the time spent in Initialize().
Definition: Ifpack_ShyLU.h:263
void Multiply(const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, bool transposeA, const CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, bool transposeB, CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &C, bool call_FillComplete_on_result=true, const std::string &label=std::string(), const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
Definition: Ifpack_ShyLU.h:230
Utilities for ShyLU.
Main data structure holding needed offset and temp variables.
Definition: shylu.h:108
bool IsComputed() const
If factor is completed, this query returns true, otherwise it returns false.
Definition: Ifpack_ShyLU.h:142
virtual int NumCompute() const
Returns the number of calls to Compute().
Definition: Ifpack_ShyLU.h:251
Main header file of ShyLU (Include main user calls)
virtual double InitializeFlops() const
Returns the number of flops in the initialization phase.
Definition: Ifpack_ShyLU.h:281
int SetLabel(std::string Label_in)
Sets label for this object.
Definition: Ifpack_ShyLU.h:213