2
// ***********************************************************************
4
// WebTrilinos: A Web Interface to Trilinos
5
// Copyright (2006) Sandia Corporation
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.
10
// This library is free software; you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as
12
// published by the Free Software Foundation; either version 2.1 of the
13
// License, or (at your option) any later version.
15
// This library is distributed in the hope that it will be useful, but
16
// WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
// Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public
21
// License along with this library; if not, write to the Free Software
22
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24
// Questions? Contact Marzio Sala (marzio.sala _AT_ gmail.com)
26
// ***********************************************************************
29
#include "Amesos_ConfigDefs.h"
32
#include "Epetra_MpiComm.h"
34
#include "Epetra_SerialComm.h"
37
#include "Epetra_RowMatrix.h"
38
#include "Epetra_Vector.h"
39
#include "Epetra_LinearProblem.h"
40
#include "Galeri_Maps.h"
41
#include "Galeri_CrsMatrices.h"
42
using namespace Teuchos;
43
using namespace Galeri;
45
// ==================== //
46
// M A I N D R I V E R //
47
// ==================== //
50
// 1.- create a linear system, stored as an
51
// Epetra_LinearProblem. The matrix corresponds
52
// to a 5pt Laplacian (2D on Cartesian grid).
53
// The user can change the global size of the problem
54
// by modifying variable NumGlobalRows.
55
// 2.- The linear system matrix, solution and rhs
56
// are distributed among the available processors,
57
// using a linear distribution. This is for
58
// simplicity only! Amesos can support any Epetra_Map.
59
// 3.- Once the linear problem is created, we
60
// create an Amesos Factory object.
61
// 4.- Using the Factory, we create the required Amesos_BaseSolver
62
// solver. Any supported (and compiled) Amesos
63
// solver can be used. If the selected solver
64
// is not available (that is, if Amesos has *not*
65
// been configured with support for this solver),
66
// the factory returns 0. Usually, Amesos_Klu
67
// is always available.
68
// 5.- At this point we can factorize the matrix,
69
// and solve the linear system. Only three methods
70
// should be used for any Amesos_BaseSolver object:
71
// 1.- NumericFactorization();
72
// 2.- SymbolicFactorization();
74
// 6.- We note that the header files of Amesos-supported
75
// libraries are *not* required in this file. They are
76
// actually needed to compile the Amesos library only.
78
// NOTE: this example can be run with any number of processors.
80
// Author: Marzio Sala, SNL 9214
81
// Last modified: Oct-05.
83
int main(int argc, char *argv[])
86
MPI_Init(&argc, &argv);
87
Epetra_MpiComm Comm(MPI_COMM_WORLD);
89
Epetra_SerialComm Comm;
92
int NumGlobalRows = 10000; // must be a square for the
94
int NumVectors = 1; // number of rhs's. Amesos
98
// Initializes an Gallery object.
99
// NOTE: this example uses the Trilinos package Galeri
100
// to define in an easy way the linear system matrix.
101
// The user can easily change the matrix type; consult the
102
// Galeri documentation for mode details.
104
// Here the problem has size nx x ny, and the 2D Cartesian
105
// grid is divided into mx x my subdomains.
106
ParameterList GaleriList;
107
GaleriList.set("nx", 100);
108
GaleriList.set("ny", 100 * Comm.NumProc());
109
GaleriList.set("mx", 1);
110
GaleriList.set("my", Comm.NumProc());
112
Epetra_Map* Map = CreateMap("Cartesian2D", Comm, GaleriList);
113
Epetra_CrsMatrix* Matrix = CreateCrsMatrix("Laplace2D", Map, GaleriList);
115
// Creates vectors for right-hand side and solution, and the
116
// linear problem container.
118
Epetra_Vector LHS(*Map); LHS.PutScalar(0.0); // zero solution
119
Epetra_Vector RHS(*Map); RHS.Random(); // random rhs
120
Epetra_LinearProblem Problem(Matrix, &LHS, &RHS);
122
// ===================================================== //
123
// B E G I N N I N G O F T H E AM E S O S P A R T //
124
// ===================================================== //
126
// Initializes the Amesos solver. This is the base class for
127
// Amesos. It is a pure virtual class (hence objects of this
128
// class cannot be allocated, and can exist only as pointers
131
Amesos_BaseSolver* Solver;
133
// Initializes the Factory. Factory is a function class (a
134
// class that contains methods only, no data). Factory
135
// will be used to create Amesos_BaseSolver derived objects.
139
Solver = Factory.Create("Klu", Problem);
141
// Parameters for all Amesos solvers are set through
142
// a call to SetParameters(List). List is a Teuchos
143
// parameter list (Amesos requires Teuchos to compile).
144
// In most cases, users can proceed without calling
145
// SetParameters(). Please refer to the Amesos guide
147
// NOTE: you can skip this call; then the solver will
148
// use default parameters.
150
// Parameters in the list are set using
151
// List.set("parameter-name", ParameterValue);
152
// In this example, we specify that we want more output.
154
Teuchos::ParameterList List;
155
List.set("PrintTiming", true);
156
List.set("PrintStatus", true);
158
Solver->SetParameters(List);
160
// Now we are ready to solve. Generally, users will
161
// call SymbolicFactorization(), then NumericFactorization(),
162
// and finally Solve(). Note that:
163
// - the numerical values of the linear system matrix
164
// are *not* required before NumericFactorization();
165
// - solution and rhs are *not* required before calling
167
if (Comm.MyPID() == 0)
168
cout << "Starting symbolic factorization..." << endl;
169
Solver->SymbolicFactorization();
171
// you can change the matrix values here
172
if (Comm.MyPID() == 0)
173
cout << "Starting numeric factorization..." << endl;
174
Solver->NumericFactorization();
176
// you can change LHS and RHS here
177
if (Comm.MyPID() == 0)
178
cout << "Starting solution phase..." << endl;
181
// =========================================== //
182
// E N D O F T H E A M E S O S P A R T //
183
// =========================================== //
185
// delete Solver. MPI calls can occur.
188
// delete the objects created by Galeri
196
return(EXIT_SUCCESS);