~chaffra/+junk/trilinos

« back to all changes in this revision

Viewing changes to packages/WebTrilinos/c++/amesos/ex_simple.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme, Christophe Prud'homme, Johannes Ring
  • Date: 2009-12-13 12:53:22 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091213125322-in0nrdjc55deqsw9
Tags: 10.0.3.dfsg-1
[Christophe Prud'homme]
* New upstream release

[Johannes Ring]
* debian/patches/libname.patch: Add prefix 'libtrilinos_' to all
  libraries. 
* debian/patches/soname.patch: Add soversion to libraries.
* debian/watch: Update download URL.
* debian/control:
  - Remove python-numeric from Build-Depends (virtual package).
  - Remove automake and autotools from Build-Depends and add cmake to
    reflect switch to CMake.
  - Add python-support to Build-Depends.
* debian/rules: 
  - Cleanup and updates for switch to CMake.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// @HEADER
2
 
// ***********************************************************************
3
 
//
4
 
//               WebTrilinos: A Web Interface to Trilinos
5
 
//                 Copyright (2006) 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
 
// 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.
14
 
//
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.
19
 
//
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
23
 
// USA
24
 
// Questions? Contact Marzio Sala (marzio.sala _AT_ gmail.com)
25
 
//
26
 
// ***********************************************************************
27
 
// @HEADER
28
 
 
29
 
#include "Amesos_ConfigDefs.h"
30
 
#ifdef HAVE_MPI
31
 
#include "mpi.h"
32
 
#include "Epetra_MpiComm.h"
33
 
#else
34
 
#include "Epetra_SerialComm.h"
35
 
#endif
36
 
#include "Amesos.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;
44
 
 
45
 
// ==================== //
46
 
// M A I N  D R I V E R //
47
 
// ==================== //
48
 
//
49
 
// This example will:
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();
73
 
//     3.- Solve();
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.
77
 
//
78
 
// NOTE: this example can be run with any number of processors.
79
 
//
80
 
// Author: Marzio Sala, SNL 9214
81
 
// Last modified: Oct-05.
82
 
 
83
 
int main(int argc, char *argv[]) 
84
 
{
85
 
#ifdef HAVE_MPI
86
 
  MPI_Init(&argc, &argv);
87
 
  Epetra_MpiComm Comm(MPI_COMM_WORLD);
88
 
#else
89
 
  Epetra_SerialComm Comm;
90
 
#endif
91
 
 
92
 
  int NumGlobalRows = 10000; // must be a square for the
93
 
                             // matrix generator.
94
 
  int NumVectors = 1;        // number of rhs's. Amesos
95
 
                             // supports single or
96
 
                             // multiple RHS.
97
 
 
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.
103
 
  //
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());
111
 
 
112
 
  Epetra_Map* Map = CreateMap("Cartesian2D", Comm, GaleriList);
113
 
  Epetra_CrsMatrix* Matrix = CreateCrsMatrix("Laplace2D", Map, GaleriList);
114
 
 
115
 
  // Creates vectors for right-hand side and solution, and the
116
 
  // linear problem container.
117
 
 
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);
121
 
 
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
 
  // ===================================================== //
125
 
 
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 
129
 
  // or references).
130
 
  //
131
 
  Amesos_BaseSolver* Solver;
132
 
 
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.
136
 
  //
137
 
  Amesos Factory;
138
 
 
139
 
  Solver = Factory.Create("Klu", Problem);
140
 
 
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
146
 
  // for more details.
147
 
  // NOTE: you can skip this call; then the solver will
148
 
  // use default parameters.
149
 
  //
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.
153
 
  //
154
 
  Teuchos::ParameterList List;
155
 
  List.set("PrintTiming", true);
156
 
  List.set("PrintStatus", true);
157
 
  
158
 
  Solver->SetParameters(List);
159
 
  
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
166
 
  //   Solve().
167
 
  if (Comm.MyPID() == 0)
168
 
    cout << "Starting symbolic factorization..." << endl;
169
 
  Solver->SymbolicFactorization();
170
 
  
171
 
  // you can change the matrix values here
172
 
  if (Comm.MyPID() == 0)
173
 
    cout << "Starting numeric factorization..." << endl;
174
 
  Solver->NumericFactorization();
175
 
  
176
 
  // you can change LHS and RHS here
177
 
  if (Comm.MyPID() == 0)
178
 
    cout << "Starting solution phase..." << endl;
179
 
  Solver->Solve();
180
 
 
181
 
  // =========================================== //
182
 
  // E N D   O F   T H E   A M E S O S   P A R T //
183
 
  // =========================================== //
184
 
 
185
 
  // delete Solver. MPI calls can occur.
186
 
  delete Solver;
187
 
    
188
 
  // delete the objects created by Galeri
189
 
  delete Matrix;
190
 
  delete Map;
191
 
 
192
 
#ifdef HAVE_MPI
193
 
  MPI_Finalize();
194
 
#endif
195
 
 
196
 
  return(EXIT_SUCCESS);
197
 
 
198
 
} // end of main()