Ifpack Package Browser (Single Doxygen Collection) Development
Loading...
Searching...
No Matches
Ifpack.cpp
Go to the documentation of this file.
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"
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"
57#ifdef HAVE_IFPACK_AMESOS
58#include "Ifpack_Amesos.h"
59#endif
60#ifdef HAVE_IFPACK_HIPS
61#include "Ifpack_HIPS.h"
62#endif
63#ifdef HAVE_IFPACK_SUPERLU
64#include "Ifpack_SILU.h"
65#endif
66#ifdef HAVE_IFPACK_SUPPORTGRAPH
67#include "Ifpack_SupportGraph.h"
68#endif
69
70#include "Ifpack_Chebyshev.h"
71#include "Ifpack_Polynomial.h"
72#include "Ifpack_Krylov.h"
73#include "Ifpack_IHSS.h"
74#include "Ifpack_SORa.h"
75
76#include "Teuchos_CommandLineProcessor.hpp"
77#include "Teuchos_StringToIntMap.hpp"
78#include "Epetra_CrsMatrix.h"
79
80
81namespace {
82
83const Teuchos::StringToIntMap
84precTypeNameToIntMap(
85 "parameter \"Prec Type\"", Ifpack::numPrecTypes, Ifpack::precTypeNames
86 );
87
88} // namespace
89
90//==============================================================================
92{
93 POINT_RELAXATION
94 ,POINT_RELAXATION_STAND_ALONE
95 ,BLOCK_RELAXATION
96 ,BLOCK_RELAXATION_STAND_ALONE
97 ,BLOCK_RELAXATION_STAND_ALONE_ILU
98 ,BLOCK_RELAXATION_STAND_ALONE_ILUT
99 ,BLOCK_RELAXATION_STAND_ALONE_IC
100#ifdef HAVE_IFPACK_SUPERLU
101 ,BLOCK_RELAXATION_STAND_ALONE_SILU
102#endif
103#ifdef HAVE_IFPACK_AMESOS
104 ,BLOCK_RELAXATION_STAND_ALONE_AMESOS
105 ,BLOCK_RELAXATION_AMESOS
106 ,AMESOS
107 ,AMESOS_STAND_ALONE
108#endif // HAVE_IFPACK_AMESOS
109 ,IC
110 ,IC_STAND_ALONE
111 ,ICT
112 ,ICT_STAND_ALONE
113 ,ILU
114 ,ILU_STAND_ALONE
115 ,ILUT
116 ,ILUT_STAND_ALONE
117#ifdef HAVE_IFPACK_SPARSKIT
118 ,SPARSKIT
119#endif // HAVE_IFPACK_SPARSKIT
120#ifdef HAVE_IFPACK_HIPS
121 ,HIPS
122#endif
123#ifdef HAVE_IFPACK_HYPRE
124 ,HYPRE
125#endif
126#ifdef HAVE_IFPACK_SUPERLU
127 ,SILU
128#endif
129#if defined (HAVE_IFPACK_SUPPORTGRAPH) && defined (HAVE_IFPACK_AMESOS)
130 ,MSF_AMESOS
131#endif
132#ifdef HAVE_IFPACK_SUPPORTGRAPH
133 ,MSF_IC
134#endif
135 ,CHEBYSHEV
136 ,POLYNOMIAL
137 ,KRYLOV
138 ,IHSS
139 ,SORA
140 ,TRIDI_RELAXATION
141 ,TRIDI_RELAXATION_STAND_ALONE
142};
143
144//==============================================================================
146{
147 "point relaxation"
148 ,"point relaxation stand-alone"
149 ,"block relaxation"
150 ,"block relaxation stand-alone"
151 ,"block relaxation stand-alone (ILU)"
152 ,"block relaxation stand-alone (ILUT)"
153 ,"block relaxation stand-alone (IC)"
154#ifdef HAVE_IFPACK_SUPERLU
155 ,"block relaxation stand-alone (SILU)"
156#endif
157#ifdef HAVE_IFPACK_AMESOS
158 ,"block relaxation stand-alone (Amesos)"
159 ,"block relaxation (Amesos)"
160 ,"Amesos"
161 ,"Amesos stand-alone"
162#endif
163 ,"IC"
164 ,"IC stand-alone"
165 ,"ICT"
166 ,"ICT stand-alone"
167 ,"ILU"
168 ,"ILU stand-alone"
169 ,"ILUT"
170 ,"ILUT stand-alone"
171#ifdef HAVE_IFPACK_SPARSKIT
172 ,"SPARSKIT"
173#endif
174#ifdef HAVE_IFPACK_HIPS
175 ,"HIPS"
176#endif
177#ifdef HAVE_IFPACK_HYPRE
178 ,"Hypre"
179#endif
180#ifdef HAVE_IFPACK_SUPERLU
181 ,"SILU"
182#endif
183#if defined (HAVE_IFPACK_SUPPORTGRAPH) && defined (HAVE_IFPACK_AMESOS)
184 ,"MSF Amesos"
185#endif
186#ifdef HAVE_IFPACK_SUPPORTGRAPH
187 ,"MSF IC"
188#endif
189 ,"Chebyshev"
190 ,"Polynomial"
191 ,"Krylov"
192 ,"IHSS"
193 ,"SORa"
194 ,"tridi relaxation"
195 ,"tridi relaxation stand-alone"
196};
197
198//==============================================================================
200{
201 true // point relaxation
202 ,true // point relaxation stand-alone
203 ,true // block relaxation
204 ,true // block relaxation stand-alone
205 ,true // block relaxation stand-alone (ILU)
206 ,true // block relaxation stand-alone (ILUT)
207 ,false // block relaxation stand-alone (IC)
208#ifdef HAVE_IFPACK_SUPERLU
209 ,true // block relaxation stand-alone (SILU)
210#endif
211#ifdef HAVE_IFPACK_AMESOS
212 ,true // block relaxation stand-alone (Amesos)
213 ,true // block relaxation (Amesos)
214 ,true // Amesos
215 ,true // Amesos stand-alone
216#endif
217 ,false // IC
218 ,false // IC stand-alone
219 ,false // ICT
220 ,false // ICT stand-alone
221 ,true // ILU
222 ,true // ILU stand-alone
223 ,true // ILUT
224 ,true // ILUT stand-alone
225#ifdef HAVE_IFPACK_SPARSKIT
226 ,true // SPARSKIT
227#endif
228#ifdef HAVE_IFPACK_HIPS
229 ,true // HIPS
230#endif
231#ifdef HAVE_IFPACK_HYPRE
232 ,true
233#endif
234#ifdef HAVE_IFPACK_SUPERLU
235 ,true // SuperLU's Supernodal ILUTP
236#endif
237#if defined (HAVE_IFPACK_SUPPORTGRAPH) && defined (HAVE_IFPACK_AMESOS)
238 ,false
239#endif
240#ifdef HAVE_IFPACK_SUPPORTGRAPH
241 ,false
242#endif
243 ,false // CHEBYSHEV
244 ,true // POLYNOMIAL
245 ,true // KRYLOV
246 ,true // IHSS
247 ,true // SORa
248 ,true // tridi relaxation
249 ,true // tridi relaxation standalone
250};
251
252//==============================================================================
254 Epetra_RowMatrix* Matrix,
255 const int Overlap,
256 bool overrideSerialDefault)
257{
258 const bool serial = (Matrix->Comm().NumProc() == 1);
259
260 switch(PrecType) {
261 case POINT_RELAXATION:
262 if (serial && !overrideSerialDefault)
263 return(new Ifpack_PointRelaxation(Matrix));
264 else
265 return(new Ifpack_AdditiveSchwarz<Ifpack_PointRelaxation>(Matrix, Overlap));
267 return(new Ifpack_PointRelaxation(Matrix));
268 case BLOCK_RELAXATION:
269 if (serial && !overrideSerialDefault)
271 else
272 return(new Ifpack_AdditiveSchwarz<
282#ifdef HAVE_IFPACK_SUPERLU
283 case BLOCK_RELAXATION_STAND_ALONE_SILU:
285#endif
286#ifdef HAVE_IFPACK_AMESOS
287 case BLOCK_RELAXATION_STAND_ALONE_AMESOS:
289 case BLOCK_RELAXATION_AMESOS:
290 return(new Ifpack_AdditiveSchwarz<
292 case AMESOS:
293 if (serial && !overrideSerialDefault)
294 return(new Ifpack_Amesos(Matrix));
295 else
296 return(new Ifpack_AdditiveSchwarz<Ifpack_Amesos>(Matrix,Overlap));
297 case AMESOS_STAND_ALONE:
298 return(new Ifpack_Amesos(Matrix));
299#endif
300 case IC:
301 if (serial && !overrideSerialDefault)
302 return(new Ifpack_IC(Matrix));
303 else
304 return(new Ifpack_AdditiveSchwarz<Ifpack_IC>(Matrix,Overlap));
305 case IC_STAND_ALONE:
306 return(new Ifpack_IC(Matrix));
307 case ICT:
308 if (serial && !overrideSerialDefault)
309 return(new Ifpack_ICT(Matrix));
310 else
311 return(new Ifpack_AdditiveSchwarz<Ifpack_ICT>(Matrix,Overlap));
312 case ICT_STAND_ALONE:
313 return(new Ifpack_ICT(Matrix));
314 case ILU:
315 if (serial && !overrideSerialDefault)
316 return(new Ifpack_ILU(Matrix));
317 else
318 return(new Ifpack_AdditiveSchwarz<Ifpack_ILU>(Matrix,Overlap));
319 case ILU_STAND_ALONE:
320 return(new Ifpack_ILU(Matrix));
321 case ILUT:
322 if (serial && !overrideSerialDefault)
323 return(new Ifpack_ILUT(Matrix));
324 else
325 return(new Ifpack_AdditiveSchwarz<Ifpack_ILUT>(Matrix,Overlap));
326 case ILUT_STAND_ALONE:
327 return(new Ifpack_ILUT(Matrix));
328#ifdef HAVE_IFPACK_SPARSKIT
329 case SPARSKIT:
330 return(new Ifpack_SPARSKIT(Matrix));
331#endif
332#ifdef HAVE_IFPACK_HIPS
333 case HIPS:
334 return(new Ifpack_HIPS(Matrix));
335#endif
336#ifdef HAVE_IFPACK_HYPRE
337 case HYPRE:
338 return(new Ifpack_Hypre(Matrix));
339#endif
340#ifdef HAVE_IFPACK_SUPERLU
341 case SILU:
342 return(new Ifpack_SILU(Matrix));
343#endif
344#if defined (HAVE_IFPACK_SUPPORTGRAPH) && defined (HAVE_IFPACK_AMESOS)
345 case MSF_AMESOS:
346 if (serial && !overrideSerialDefault)
347 return(new Ifpack_SupportGraph<Ifpack_Amesos>(Matrix));
348 else
350#endif
351#ifdef HAVE_IFPACK_SUPPORTGRAPH
352 case MSF_IC:
353 if (serial && !overrideSerialDefault)
355 else
356 return(new Ifpack_AdditiveSchwarz<Ifpack_SupportGraph<Ifpack_IC> >(Matrix,Overlap));
357#endif
358 case CHEBYSHEV:
359 return(new Ifpack_Chebyshev(Matrix));
360 case POLYNOMIAL:
361 return(new Ifpack_Polynomial(Matrix));
362 case KRYLOV:
363 return(new Ifpack_Krylov(Matrix));
364 // local krylov
365 // if (serial && !overrideSerialDefault)
366 // return(new Ifpack_Krylov(Matrix));
367 // else
368 // return(new Ifpack_AdditiveSchwarz<Ifpack_Krylov>(Matrix, Overlap));
369#ifdef HAVE_IFPACK_EPETRAEXT
370 case IHSS:
371 return(new Ifpack_IHSS(Matrix));
372 case SORA:
373 return(new Ifpack_SORa(Matrix));
374#endif
375 case TRIDI_RELAXATION:
376 if (serial && !overrideSerialDefault)
378 else
379 return(new Ifpack_AdditiveSchwarz<
383 default:
384 TEUCHOS_TEST_FOR_EXCEPT(true);
385 // The only way to get here is if some code developer does a cast like
386 // (EPrecType)(anyNumber). You can never get here by passing in a
387 // std::string value for the preconditioner!
388 } // end switch
389 //return 0; // unreachable
390}
391
392//==============================================================================
393Ifpack_Preconditioner* Ifpack::Create(const std::string PrecType,
394 Epetra_RowMatrix* Matrix,
395 const int Overlap,
396 bool overrideSerialDefault)
397{
398 try {
399 return Ifpack::Create(Teuchos::get<EPrecType>(::precTypeNameToIntMap,PrecType),Matrix,Overlap,overrideSerialDefault);
400 }
401 catch( const Teuchos::StringToIntMap::DoesNotExist &excpt ) {
402 // The old implementation of this function just silently returned a NULL
403 // when a preconditiner type name was not recognized. If you like this
404 // behavior then you should use this function. If you do not like this
405 // behavior, then consider using the Ifpack/Thyra adapter
406 // Thyra::IfpackPreconditionerFactory or better yet the Stratimikos
407 // wrapper class Stratimikos::DefaultLinearSolverBuilder.
408 }
409 return 0;
410}
411
412// ======================================================================
413int Ifpack::SetParameters(int argc, char* argv[],
414 Teuchos::ParameterList& List, std::string& PrecType,
415 int& Overlap)
416{
417 // THIS FUNCTION IS VERY INCOMPLETE...
418
419 Teuchos::CommandLineProcessor CLP;
420
421 // prec type
422 std::string ifp_prec_type = "ILU";
423 CLP.setOption("ifp-prec-type",&ifp_prec_type,"Preconditioner type");
424 // overlap among the processors
425 int ifp_overlap = 0;
426 CLP.setOption("ifp-overlap",&ifp_overlap,"Overlap among processors");
427 // relaxation type
428 std::string ifp_relax_type = "Jacobi";
429 CLP.setOption("ifp-relax-type",&ifp_relax_type,"Relaxation type");
430 // sweeps (for relax only)
431 int ifp_relax_sweeps = 1;
432 CLP.setOption("ifp-relax-sweeps",
433 &ifp_relax_sweeps,"Number of sweeps for relaxation");
434 // damping (for relax only)
435 double ifp_relax_damping = 1.0;
436 CLP.setOption("ifp-relax-damping",
437 &ifp_relax_damping,"Damping for relaxation");
438 // partitioner type (for block relaxation only)
439 std::string ifp_part_type = "greedy";
440 CLP.setOption("ifp-part-type",&ifp_part_type,"Partitioner type");
441 // number of local parts (for block relaxation only)
442 int ifp_part_local = 1;
443 CLP.setOption("ifp-part-local",&ifp_part_local,"number of local partitions");
444
445 // allow users to specify other options for other packages
446 CLP.recogniseAllOptions(false);
447 CLP.throwExceptions(false);
448 CLP.parse(argc,argv);
449
450 // I cannot really set those in the List, I pass them back to the user
451 PrecType = ifp_prec_type;
452 Overlap = ifp_overlap;
453
454 // set the list here
455 List.set("relaxation: type", ifp_relax_type);
456 List.set("relaxation: sweeps", ifp_relax_sweeps);
457 List.set("relaxation: damping factor", ifp_relax_damping);
458 List.set("partitioner: type", ifp_part_type);
459 List.set("partitioner: local parts", ifp_part_local);
460
461 return(0);
462}
virtual int NumProc() const=0
virtual const Epetra_Comm & Comm() const=0
Ifpack_AdditiveSchwarz: a class to define Additive Schwarz preconditioners of Epetra_RowMatrix's.
Ifpack_Amesos: a class to use Amesos' factorizations as preconditioners.
Definition: Ifpack_Amesos.h:81
Ifpack_BlockRelaxation: a class to define block relaxation preconditioners of Epetra_RowMatrix's.
Ifpack_Chebyshev: class for preconditioning with Chebyshev polynomials in Ifpack.
Ifpack_ICT: A class for constructing and using an incomplete Cholesky factorization of a given Epetra...
Definition: Ifpack_ICT.h:83
Ifpack_IC: A class for constructing and using an incomplete Cholesky factorization of a given Epetra_...
Definition: Ifpack_IC.h:80
Ifpack_ILUT: A class for constructing and using an incomplete LU factorization of a given Epetra_RowM...
Definition: Ifpack_ILUT.h:81
Ifpack_ILU: A class for constructing and using an incomplete lower/upper (ILU) factorization of a giv...
Definition: Ifpack_ILU.h:83
Ifpack_Krylov: class for smoothing with Krylov solvers in Ifpack.
Definition: Ifpack_Krylov.h:81
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_Preconditioner: basic class for preconditioning in Ifpack.
Ifpack_SparseContainer: a class for storing and solving linear systems using sparse matrices.
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:253
static const int numPrecTypes
Definition: Ifpack.h:195
EPrecType
Enum for the type of preconditioner.
Definition: Ifpack.h:142
@ IC
Definition: Ifpack.h:159
@ POINT_RELAXATION
Definition: Ifpack.h:143
@ IHSS
Definition: Ifpack.h:188
@ BLOCK_RELAXATION_STAND_ALONE_IC
Definition: Ifpack.h:149
@ IC_STAND_ALONE
Definition: Ifpack.h:160
@ POLYNOMIAL
Definition: Ifpack.h:186
@ BLOCK_RELAXATION_STAND_ALONE
Definition: Ifpack.h:146
@ ILU
Definition: Ifpack.h:163
@ SORA
Definition: Ifpack.h:189
@ TRIDI_RELAXATION_STAND_ALONE
Definition: Ifpack.h:191
@ ILU_STAND_ALONE
Definition: Ifpack.h:164
@ TRIDI_RELAXATION
Definition: Ifpack.h:190
@ ILUT_STAND_ALONE
Definition: Ifpack.h:166
@ ILUT
Definition: Ifpack.h:165
@ ICT_STAND_ALONE
Definition: Ifpack.h:162
@ BLOCK_RELAXATION_STAND_ALONE_ILU
Definition: Ifpack.h:147
@ ICT
Definition: Ifpack.h:161
@ KRYLOV
Definition: Ifpack.h:187
@ BLOCK_RELAXATION
Definition: Ifpack.h:145
@ POINT_RELAXATION_STAND_ALONE
Definition: Ifpack.h:144
@ BLOCK_RELAXATION_STAND_ALONE_ILUT
Definition: Ifpack.h:148
@ CHEBYSHEV
Definition: Ifpack.h:185
static const bool supportsUnsymmetric[numPrecTypes]
List of bools that determines if the preconditioner type supports unsymmetric matrices.
Definition: Ifpack.h:230
int SetParameters(int argc, char *argv[], Teuchos::ParameterList &List, std::string &PrecType, int &Overlap)
Sets the options in List from the command line.
Definition: Ifpack.cpp:413
static const char * precTypeNames[numPrecTypes]
List of preconditioner types as std::string values.
Definition: Ifpack.h:226
static const EPrecType precTypeValues[numPrecTypes]
List of the preconditioner types as enum values .
Definition: Ifpack.h:223