Ifpack Package Browser (Single Doxygen Collection)
Development
Toggle main menu visibility
Loading...
Searching...
No Matches
example
Ifpack_ex_Amesos.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
44
#ifdef HAVE_MPI
45
#include "
Epetra_MpiComm.h
"
46
#else
47
#include "
Epetra_SerialComm.h
"
48
#endif
49
#include "
Epetra_CrsMatrix.h
"
50
#include "
Epetra_MultiVector.h
"
51
#include "
Epetra_Map.h
"
52
#include "
Epetra_BlockMap.h
"
53
#include "
Epetra_LinearProblem.h
"
54
#include "Galeri_Maps.h"
55
#include "Galeri_CrsMatrices.h"
56
#include "Teuchos_ParameterList.hpp"
57
#include "Teuchos_RefCountPtr.hpp"
58
#include "AztecOO.h"
59
#include "
Ifpack.h
"
60
61
int
main
(
int
argc,
char
*argv[])
62
{
63
64
// initialize MPI and Epetra communicator
65
#ifdef HAVE_MPI
66
MPI_Init(&argc,&argv);
67
Epetra_MpiComm
Comm( MPI_COMM_WORLD );
68
#else
69
Epetra_SerialComm
Comm;
70
#endif
71
72
Teuchos::ParameterList GaleriList;
73
74
// The problem is defined on a 2D grid, global size is nx * nx.
75
int
nx = 30;
76
GaleriList.set(
"nx"
, nx);
77
GaleriList.set(
"ny"
, nx * Comm.
NumProc
());
78
GaleriList.set(
"mx"
, 1);
79
GaleriList.set(
"my"
, Comm.
NumProc
());
80
Teuchos::RefCountPtr<Epetra_Map> Map = Teuchos::rcp( Galeri::CreateMap(
"Cartesian2D"
, Comm, GaleriList) );
81
Teuchos::RefCountPtr<Epetra_RowMatrix> A = Teuchos::rcp( Galeri::CreateCrsMatrix(
"Laplace2D"
, &*Map, GaleriList) );
82
83
// =============================================================== //
84
// B E G I N N I N G O F I F P A C K C O N S T R U C T I O N //
85
// =============================================================== //
86
87
Teuchos::ParameterList List;
88
89
// allocates an IFPACK factory. No data is associated
90
// to this object (only method Create()).
91
Ifpack
Factory;
92
93
// create the preconditioner. For valid PrecType values,
94
// please check the documentation
95
std::string PrecType =
"Amesos"
;
96
int
OverlapLevel = 2;
// must be >= 0. If Comm.NumProc() == 1,
97
// it is ignored.
98
99
Teuchos::RefCountPtr<Ifpack_Preconditioner> Prec = Teuchos::rcp( Factory.
Create
(PrecType, &*A, OverlapLevel) );
100
assert(Prec != Teuchos::null);
101
102
// specify the Amesos solver to be used.
103
// If the selected solver is not available,
104
// IFPACK will try to use Amesos' KLU (which is usually always
105
// compiled). Amesos' serial solvers are:
106
// "Amesos_Klu", "Amesos_Umfpack", "Amesos_Superlu"
107
List.set(
"amesos: solver type"
,
"Amesos_Klu"
);
108
109
// sets the parameters
110
IFPACK_CHK_ERR
(Prec->SetParameters(List));
111
112
// initialize the preconditioner. At this point the matrix must
113
// have been FillComplete()'d, but actual values are ignored.
114
// At this call, Amesos will perform the symbolic factorization.
115
IFPACK_CHK_ERR
(Prec->Initialize());
116
117
// Builds the preconditioners, by looking for the values of
118
// the matrix. At this call, Amesos will perform the
119
// numeric factorization.
120
IFPACK_CHK_ERR
(Prec->Compute());
121
122
// =================================================== //
123
// E N D O F I F P A C K C O N S T R U C T I O N //
124
// =================================================== //
125
126
// At this point, we need some additional objects
127
// to define and solve the linear system.
128
129
// defines LHS and RHS
130
Epetra_Vector
LHS(A->OperatorDomainMap());
131
Epetra_Vector
RHS
(A->OperatorDomainMap());
132
133
// solution is constant
134
LHS.
PutScalar
(1.0);
135
// now build corresponding RHS
136
A->Apply(LHS,
RHS
);
137
138
// now randomize the solution
139
RHS
.Random();
140
141
// need an Epetra_LinearProblem to define AztecOO solver
142
Epetra_LinearProblem
Problem(&*A,&LHS,&
RHS
);
143
144
// now we can allocate the AztecOO solver
145
AztecOO
Solver
(Problem);
146
147
// specify solver
148
Solver
.SetAztecOption(AZ_solver,AZ_gmres);
149
Solver
.SetAztecOption(AZ_output,32);
150
151
// HERE WE SET THE IFPACK PRECONDITIONER
152
Solver
.SetPrecOperator(&*Prec);
153
154
// .. and here we solve
155
// NOTE: with one process, the solver must converge in
156
// one iteration.
157
Solver
.Iterate(1550,1e-8);
158
159
#ifdef HAVE_MPI
160
MPI_Finalize() ;
161
#endif
162
163
return
(EXIT_SUCCESS);
164
}
Solver
Solver
Epetra_BlockMap.h
Epetra_CrsMatrix.h
Epetra_LinearProblem.h
Epetra_Map.h
Epetra_MpiComm.h
Epetra_MultiVector.h
Epetra_SerialComm.h
Ifpack.h
Ifpack_ConfigDefs.h
IFPACK_CHK_ERR
#define IFPACK_CHK_ERR(ifpack_err)
Definition
Ifpack_ConfigDefs.h:125
main
int main(int argc, char *argv[])
Definition
Ifpack_ex_Amesos.cpp:61
RHS
#define RHS(a)
Definition
MatGenFD.c:60
Epetra_LinearProblem
Epetra_MpiComm
Epetra_MpiComm::NumProc
int NumProc() const
Epetra_MultiVector::PutScalar
int PutScalar(double ScalarConstant)
Epetra_SerialComm
Epetra_Vector
Ifpack::Create
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
Ifpack
Definition
ifp_parameters.cpp:50
Generated by
1.17.0