IFPACK  Development
 All Classes Files Functions Variables Enumerations Friends Pages
Ifpack.cpp
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack: Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2002) 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 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 #include "Ifpack_ConfigDefs.h"
43 #include "Ifpack.h"
44 #include "Ifpack_Preconditioner.h"
45 #include "Ifpack_PointRelaxation.h"
46 #include "Ifpack_BlockRelaxation.h"
47 #include "Ifpack_IC.h"
48 #include "Ifpack_ICT.h"
49 #include "Ifpack_ILU.h"
50 #include "Ifpack_SILU.h"
51 #include "Ifpack_ILUT.h"
52 #include "Ifpack_SPARSKIT.h"
53 #include "Ifpack_AdditiveSchwarz.h"
54 #include "Ifpack_DenseContainer.h"
55 #include "Ifpack_SparseContainer.h"
56 #ifdef HAVE_IFPACK_AMESOS
57 #include "Ifpack_Amesos.h"
58 #endif
59 #ifdef HAVE_IFPACK_HIPS
60 #include "Ifpack_HIPS.h"
61 #endif
62 #ifdef HAVE_IFPACK_SUPERLU
63 #include "Ifpack_SILU.h"
64 #endif
65 #ifdef HAVE_IFPACK_SUPPORTGRAPH
66 #include "Ifpack_SupportGraph.h"
67 #endif
68 
69 #include "Ifpack_Chebyshev.h"
70 #include "Ifpack_Polynomial.h"
71 #include "Ifpack_Krylov.h"
72 #include "Ifpack_IHSS.h"
73 #include "Ifpack_SORa.h"
74 
75 #include "Teuchos_CommandLineProcessor.hpp"
76 #include "Teuchos_StringToIntMap.hpp"
77 #include "Epetra_CrsMatrix.h"
78 
79 
80 namespace {
81 
82 const Teuchos::StringToIntMap
83 precTypeNameToIntMap(
84  "parameter \"Prec Type\"", Ifpack::numPrecTypes, Ifpack::precTypeNames
85  );
86 
87 } // namespace
88 
89 //==============================================================================
91 {
92  POINT_RELAXATION
93  ,POINT_RELAXATION_STAND_ALONE
94  ,BLOCK_RELAXATION
95  ,BLOCK_RELAXATION_STAND_ALONE
96  ,BLOCK_RELAXATION_STAND_ALONE_ILU
97  ,BLOCK_RELAXATION_STAND_ALONE_ILUT
98  ,BLOCK_RELAXATION_STAND_ALONE_IC
99 #ifdef HAVE_IFPACK_SUPERLU
100  ,BLOCK_RELAXATION_STAND_ALONE_SILU
101 #endif
102 #ifdef HAVE_IFPACK_AMESOS
103  ,BLOCK_RELAXATION_STAND_ALONE_AMESOS
104  ,BLOCK_RELAXATION_AMESOS
105  ,AMESOS
106  ,AMESOS_STAND_ALONE
107 #endif // HAVE_IFPACK_AMESOS
108  ,IC
109  ,IC_STAND_ALONE
110  ,ICT
111  ,ICT_STAND_ALONE
112  ,ILU
113  ,ILU_STAND_ALONE
114  ,ILUT
115  ,ILUT_STAND_ALONE
116 #ifdef HAVE_IFPACK_SPARSKIT
117  ,SPARSKIT
118 #endif // HAVE_IFPACK_SPARSKIT
119 #ifdef HAVE_IFPACK_HIPS
120  ,HIPS
121 #endif
122 #ifdef HAVE_HYPRE
123  ,HYPRE
124 #endif
125 #ifdef HAVE_IFPACK_SUPERLU
126  ,SILU
127 #endif
128 #if defined (HAVE_IFPACK_SUPPORTGRAPH) && defined (HAVE_IFPACK_AMESOS)
129  ,MSF_AMESOS
130 #endif
131 #ifdef HAVE_IFPACK_SUPPORTGRAPH
132  ,MSF_IC
133 #endif
134  ,CHEBYSHEV
135  ,POLYNOMIAL
136  ,KRYLOV
137  ,IHSS
138  ,SORA
139 };
140 
141 //==============================================================================
143 {
144  "point relaxation"
145  ,"point relaxation stand-alone"
146  ,"block relaxation"
147  ,"block relaxation stand-alone"
148  ,"block relaxation stand-alone (ILU)"
149  ,"block relaxation stand-alone (ILUT)"
150  ,"block relaxation stand-alone (IC)"
151 #ifdef HAVE_IFPACK_SUPERLU
152  ,"block relaxation stand-alone (SILU)"
153 #endif
154 #ifdef HAVE_IFPACK_AMESOS
155  ,"block relaxation stand-alone (Amesos)"
156  ,"block relaxation (Amesos)"
157  ,"Amesos"
158  ,"Amesos stand-alone"
159 #endif
160  ,"IC"
161  ,"IC stand-alone"
162  ,"ICT"
163  ,"ICT stand-alone"
164  ,"ILU"
165  ,"ILU stand-alone"
166  ,"ILUT"
167  ,"ILUT stand-alone"
168 #ifdef HAVE_IFPACK_SPARSKIT
169  ,"SPARSKIT"
170 #endif
171 #ifdef HAVE_IFPACK_HIPS
172  ,"HIPS"
173 #endif
174 #ifdef HAVE_HYPRE
175  ,"Hypre"
176 #endif
177 #ifdef HAVE_IFPACK_SUPERLU
178  ,"SILU"
179 #endif
180 #if defined (HAVE_IFPACK_SUPPORTGRAPH) && defined (HAVE_IFPACK_AMESOS)
181  ,"MSF Amesos"
182 #endif
183 #ifdef HAVE_IFPACK_SUPPORTGRAPH
184  ,"MSF IC"
185 #endif
186  ,"Chebyshev"
187  ,"Polynomial"
188  ,"Krylov"
189  ,"IHSS"
190  ,"SORa"
191 };
192 
193 //==============================================================================
195 {
196  true // point relaxation
197  ,true // point relaxation stand-alone
198  ,true // block relaxation
199  ,true // block relaxation stand-alone
200  ,true // block relaxation stand-alone (ILU)
201  ,true // block relaxation stand-alone (ILUT)
202  ,false // block relaxation stand-alone (IC)
203 #ifdef HAVE_IFPACK_SUPERLU
204  ,true // block relaxation stand-alone (SILU)
205 #endif
206 #ifdef HAVE_IFPACK_AMESOS
207  ,true // block relaxation stand-alone (Amesos)
208  ,true // block relaxation (Amesos)
209  ,true // Amesos
210  ,true // Amesos stand-alone
211 #endif
212  ,false // IC
213  ,false // IC stand-alone
214  ,false // ICT
215  ,false // ICT stand-alone
216  ,true // ILU
217  ,true // ILU stand-alone
218  ,true // ILUT
219  ,true // ILUT stand-alone
220 #ifdef HAVE_IFPACK_SPARSKIT
221  ,true // SPARSKIT
222 #endif
223 #ifdef HAVE_IFPACK_HIPS
224  ,true // HIPS
225 #endif
226 #ifdef HAVE_HYPRE
227  ,true
228 #endif
229 #ifdef HAVE_IFPACK_SUPERLU
230  ,true // SuperLU's Supernodal ILUTP
231 #endif
232 #if defined (HAVE_IFPACK_SUPPORTGRAPH) && defined (HAVE_IFPACK_AMESOS)
233  ,false
234 #endif
235 #ifdef HAVE_IFPACK_SUPPORTGRAPH
236  ,false
237 #endif
238  ,false // CHEBYSHEV
239  ,true // POLYNOMIAL
240  ,true // KRYLOV
241  ,true // IHSS
242  ,true // SORa
243 };
244 
245 //==============================================================================
247  Epetra_RowMatrix* Matrix,
248  const int Overlap,
249  bool overrideSerialDefault)
250 {
251  const bool serial = (Matrix->Comm().NumProc() == 1);
252 
253  switch(PrecType) {
254  case POINT_RELAXATION:
255  if (serial && !overrideSerialDefault)
256  return(new Ifpack_PointRelaxation(Matrix));
257  else
258  return(new Ifpack_AdditiveSchwarz<Ifpack_PointRelaxation>(Matrix, Overlap));
259  case POINT_RELAXATION_STAND_ALONE:
260  return(new Ifpack_PointRelaxation(Matrix));
261  case BLOCK_RELAXATION:
262  if (serial && !overrideSerialDefault)
264  else
265  return(new Ifpack_AdditiveSchwarz<
267  case BLOCK_RELAXATION_STAND_ALONE:
269  case BLOCK_RELAXATION_STAND_ALONE_ILU:
271  case BLOCK_RELAXATION_STAND_ALONE_ILUT:
273  case BLOCK_RELAXATION_STAND_ALONE_IC:
275 #ifdef HAVE_IFPACK_SUPERLU
276  case BLOCK_RELAXATION_STAND_ALONE_SILU:
278 #endif
279 #ifdef HAVE_IFPACK_AMESOS
280  case BLOCK_RELAXATION_STAND_ALONE_AMESOS:
282  case BLOCK_RELAXATION_AMESOS:
283  return(new Ifpack_AdditiveSchwarz<
285  case AMESOS:
286  if (serial && !overrideSerialDefault)
287  return(new Ifpack_Amesos(Matrix));
288  else
289  return(new Ifpack_AdditiveSchwarz<Ifpack_Amesos>(Matrix,Overlap));
290  case AMESOS_STAND_ALONE:
291  return(new Ifpack_Amesos(Matrix));
292 #endif
293  case IC:
294  if (serial && !overrideSerialDefault)
295  return(new Ifpack_IC(Matrix));
296  else
297  return(new Ifpack_AdditiveSchwarz<Ifpack_IC>(Matrix,Overlap));
298  case IC_STAND_ALONE:
299  return(new Ifpack_IC(Matrix));
300  case ICT:
301  if (serial && !overrideSerialDefault)
302  return(new Ifpack_ICT(Matrix));
303  else
304  return(new Ifpack_AdditiveSchwarz<Ifpack_ICT>(Matrix,Overlap));
305  case ICT_STAND_ALONE:
306  return(new Ifpack_ICT(Matrix));
307  case ILU:
308  if (serial && !overrideSerialDefault)
309  return(new Ifpack_ILU(Matrix));
310  else
311  return(new Ifpack_AdditiveSchwarz<Ifpack_ILU>(Matrix,Overlap));
312  case ILU_STAND_ALONE:
313  return(new Ifpack_ILU(Matrix));
314  case ILUT:
315  if (serial && !overrideSerialDefault)
316  return(new Ifpack_ILUT(Matrix));
317  else
318  return(new Ifpack_AdditiveSchwarz<Ifpack_ILUT>(Matrix,Overlap));
319  case ILUT_STAND_ALONE:
320  return(new Ifpack_ILUT(Matrix));
321 #ifdef HAVE_IFPACK_SPARSKIT
322  case SPARSKIT:
323  return(new Ifpack_SPARSKIT(Matrix));
324 #endif
325 #ifdef HAVE_IFPACK_HIPS
326  case HIPS:
327  return(new Ifpack_HIPS(Matrix));
328 #endif
329 #ifdef HAVE_HYPRE
330  case HYPRE:
331  return(new Ifpack_Hypre(Matrix));
332 #endif
333 #ifdef HAVE_IFPACK_SUPERLU
334  case SILU:
335  return(new Ifpack_SILU(Matrix));
336 #endif
337 #if defined (HAVE_IFPACK_SUPPORTGRAPH) && defined (HAVE_IFPACK_AMESOS)
338  case MSF_AMESOS:
339  if (serial && !overrideSerialDefault)
340  return(new Ifpack_SupportGraph<Ifpack_Amesos>(Matrix));
341  else
342  return(new Ifpack_AdditiveSchwarz<Ifpack_SupportGraph<Ifpack_Amesos> >(Matrix,Overlap));
343 #endif
344 #ifdef HAVE_IFPACK_SUPPORTGRAPH
345  case MSF_IC:
346  if (serial && !overrideSerialDefault)
348  else
349  return(new Ifpack_AdditiveSchwarz<Ifpack_SupportGraph<Ifpack_IC> >(Matrix,Overlap));
350 #endif
351  case CHEBYSHEV:
352  return(new Ifpack_Chebyshev(Matrix));
353  case POLYNOMIAL:
354  return(new Ifpack_Polynomial(Matrix));
355  case KRYLOV:
356  if (serial && !overrideSerialDefault)
357  return(new Ifpack_Krylov(Matrix));
358  else
359  return(new Ifpack_AdditiveSchwarz<Ifpack_Krylov>(Matrix, Overlap));
360 #ifdef HAVE_IFPACK_EPETRAEXT
361  case IHSS:
362  return(new Ifpack_IHSS(Matrix));
363  case SORA:
364  return(new Ifpack_SORa(Matrix));
365 #endif
366  default:
367  TEUCHOS_TEST_FOR_EXCEPT(true);
368  // The only way to get here is if some code developer does a cast like
369  // (EPrecType)(anyNumber). You can never get here by passing in a
370  // string value for the preconditioner!
371  } // end switch
372  return 0; // This will never ever be executed!
373 }
374 
375 //==============================================================================
376 Ifpack_Preconditioner* Ifpack::Create(const string PrecType,
377  Epetra_RowMatrix* Matrix,
378  const int Overlap,
379  bool overrideSerialDefault)
380 {
381  try {
382  return Ifpack::Create(Teuchos::get<EPrecType>(::precTypeNameToIntMap,PrecType),Matrix,Overlap,overrideSerialDefault);
383  }
384  catch( const Teuchos::StringToIntMap::DoesNotExist &excpt ) {
385  // The old implementation of this function just silently returned a NULL
386  // when a preconditiner type name was not recognized. If you like this
387  // behavior then you should use this function. If you do not like this
388  // behavior, then consider using the Ifpack/Thyra adapter
389  // Thyra::IfpackPreconditionerFactory or better yet the Stratimikos
390  // wrapper class Stratimikos::DefaultLinearSolverBuilder.
391  }
392  return 0;
393 }
394 
395 // ======================================================================
396 int Ifpack::SetParameters(int argc, char* argv[],
397  Teuchos::ParameterList& List, string& PrecType,
398  int& Overlap)
399 {
400  // THIS FUNCTION IS VERY INCOMPLETE...
401 
402  Teuchos::CommandLineProcessor CLP;
403 
404  // prec type
405  string ifp_prec_type = "ILU";
406  CLP.setOption("ifp-prec-type",&ifp_prec_type,"Preconditioner type");
407  // overlap among the processors
408  int ifp_overlap = 0;
409  CLP.setOption("ifp-overlap",&ifp_overlap,"Overlap among processors");
410  // relaxation type
411  string ifp_relax_type = "Jacobi";
412  CLP.setOption("ifp-relax-type",&ifp_relax_type,"Relaxation type");
413  // sweeps (for relax only)
414  int ifp_relax_sweeps = 1;
415  CLP.setOption("ifp-relax-sweeps",
416  &ifp_relax_sweeps,"Number of sweeps for relaxation");
417  // damping (for relax only)
418  double ifp_relax_damping = 1.0;
419  CLP.setOption("ifp-relax-damping",
420  &ifp_relax_damping,"Damping for relaxation");
421  // partitioner type (for block relaxation only)
422  string ifp_part_type = "greedy";
423  CLP.setOption("ifp-part-type",&ifp_part_type,"Partitioner type");
424  // number of local parts (for block relaxation only)
425  int ifp_part_local = 1;
426  CLP.setOption("ifp-part-local",&ifp_part_local,"number of local partitions");
427 
428  // allow users to specify other options for other packages
429  CLP.recogniseAllOptions(false);
430  CLP.throwExceptions(false);
431  CLP.parse(argc,argv);
432 
433  // I cannot really set those in the List, I pass them back to the user
434  PrecType = ifp_prec_type;
435  Overlap = ifp_overlap;
436 
437  // set the list here
438  List.set("relaxation: type", ifp_relax_type);
439  List.set("relaxation: sweeps", ifp_relax_sweeps);
440  List.set("relaxation: damping factor", ifp_relax_damping);
441  List.set("partitioner: type", ifp_part_type);
442  List.set("partitioner: local parts", ifp_part_local);
443 
444  return(0);
445 }
static const int numPrecTypes
Definition: Ifpack.h:193
Ifpack_BlockRelaxation: a class to define block relaxation preconditioners of Epetra_RowMatrix's.
static const EPrecType precTypeValues[numPrecTypes]
List of the preconditioner types as enum values .
Definition: Ifpack.h:221
EPrecType
Enum for the type of preconditioner.
Definition: Ifpack.h:142
A wrapper to SuperLU 4.0's supernodal ILUT w/ partial pivoting.
Definition: Ifpack_SILU.h:83
int SetParameters(int argc, char *argv[], Teuchos::ParameterList &List, string &PrecType, int &Overlap)
Sets the options in List from the command line.
Definition: Ifpack.cpp:396
static const char * precTypeNames[numPrecTypes]
List of preconditioner types as string values.
Definition: Ifpack.h:224
Ifpack_ILU: A class for constructing and using an incomplete lower/upper (ILU) factorization of a giv...
Definition: Ifpack_ILU.h:83
Ifpack_Amesos: a class to use Amesos' factorizations as preconditioners.
Definition: Ifpack_Amesos.h:81
Ifpack_AdditiveSchwarz: a class to define Additive Schwarz preconditioners of Epetra_RowMatrix's.
Ifpack_SparseContainer: a class for storing and solving linear systems using sparse matrices...
Ifpack_Chebyshev: class for preconditioning with Chebyshev polynomials in Ifpack. ...
Ifpack_Preconditioner: basic class for preconditioning in Ifpack.
Ifpack_PointRelaxation: a class to define point relaxation preconditioners of for Epetra_RowMatrix's...
Ifpack_Polynomial: class for preconditioning with least squares polynomials in Ifpack.
Ifpack_Krylov: class for smoothing with Krylov solvers in Ifpack.
Definition: Ifpack_Krylov.h:81
Ifpack_IC: A class for constructing and using an incomplete Cholesky factorization of a given Epetra_...
Definition: Ifpack_IC.h:80
Ifpack_ICT: A class for constructing and using an incomplete Cholesky factorization of a given Epetra...
Definition: Ifpack_ICT.h:83
static Ifpack_Preconditioner * Create(EPrecType PrecType, Epetra_RowMatrix *Matrix, const int overlap=0, bool overrideSerialDefault=false)
Creates an instance of Ifpack_Preconditioner given the enum value of the preconditioner type (can not...
Definition: Ifpack.cpp:246
static const bool supportsUnsymmetric[numPrecTypes]
List of bools that determines if the preconditioner type supports unsymmetric matrices.
Definition: Ifpack.h:228
Ifpack_ILUT: A class for constructing and using an incomplete LU factorization of a given Epetra_RowM...
Definition: Ifpack_ILUT.h:81