Galeri Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxx_main.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Galeri: Finite Element and Matrix Generation Package
4 //
5 // Copyright 2006 ETHZ/NTESS and the Galeri contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Galeri_Maps.h"
11 #include "Galeri_CrsMatrices.h"
12 #include "Galeri_Utils.h"
13 #ifdef HAVE_MPI
14 #include "Epetra_MpiComm.h"
15 #include "mpi.h"
16 #else
17 #include "Epetra_SerialComm.h"
18 #endif
19 #include "Epetra_Map.h"
20 #include "Epetra_Vector.h"
21 #include "Epetra_CrsMatrix.h"
22 #include "Epetra_LinearProblem.h"
24 
25 using namespace Galeri;
26 
27 // =========== //
28 // main driver //
29 // =========== //
30 
31 int main(int argc, char* argv[]) {
32 #ifdef HAVE_MPI
33  MPI_Init(&argc, &argv);
34  Epetra_MpiComm Comm(MPI_COMM_WORLD);
35 #else
36  Epetra_SerialComm Comm;
37 #endif
38 
39  // Here we create the linear problem
40  //
41  // Matrix * LHS = RHS
42  //
43  // with Matrix arising from a 5-point formula discretization.
44 
45  Epetra_Map* Map = 0;
46  Epetra_RowMatrix* Matrix = 0;
47 
48  Teuchos::ParameterList GaleriList;
49  // dimension of the problem is nx x ny
50  GaleriList.set("nx", 10 * Comm.NumProc());
51  GaleriList.set("ny", 10);
52  // total number of processors is mx x my
53  GaleriList.set("mx", Comm.NumProc());
54  GaleriList.set("my", 1);
55 
56  try {
57  Map = CreateMap("Cartesian2D", Comm, GaleriList);
58  Matrix = CreateCrsMatrix("Laplace2D", Map, GaleriList);
59  Epetra_Vector ExactSolution(*Map);
60  ExactSolution.Random();
61  Epetra_Vector LHS(*Map);
62  LHS.PutScalar(0.0);
63  Epetra_Vector RHS(*Map);
64 
65  Matrix->Multiply(false, ExactSolution, RHS);
66 
67  Epetra_LinearProblem Problem(Matrix, &LHS, &RHS);
68 
69  // at this point any object that understand Epetra_LinearProblem can be
70  // used, for example AztecOO, Amesos. IFPACK and ML can be used to define a
71  // preconditioner for Matrix. Here we use a simple solver, based on
72  // LAPACK, that is meant for simple testing only.
73 
74  Solve(Problem);
75 
76  // and we compute the norm of the true residual.
77  double ResidualNorm = ComputeNorm(Matrix, &LHS, &RHS);
78 
79  if (Comm.MyPID() == 0)
80  cout << ResidualNorm << endl;
81 
82  delete Map;
83  delete Matrix;
84  } catch (Galeri::Exception& rhs) {
85  if (Comm.MyPID() == 0)
86  rhs.Print();
87  exit(EXIT_FAILURE);
88  }
89 
90 #ifdef HAVE_MPI
91  MPI_Finalize();
92 #endif
93 
94  return (EXIT_SUCCESS);
95 }
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
int MyPID() const
int NumProc() const
virtual int Multiply(bool TransA, const Epetra_MultiVector &X, Epetra_MultiVector &Y) const =0
int main(int argc, char *argv[])
Definition: CrsMatrix.cpp:29
int Solve(int, TYPE *, TYPE *, TYPE *)