| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// MueLu: A package for multigrid based preconditioning |
| 4 |
// |
| 5 |
// Copyright 2012 NTESS and the MueLu contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#include <iostream> |
| 11 |
|
| 12 |
// Teuchos |
| 13 |
#include <Teuchos_RCP.hpp> |
| 14 |
#include <Teuchos_DefaultComm.hpp> |
| 15 |
#include <Teuchos_StandardCatchMacros.hpp> |
| 16 |
|
| 17 |
// Galeri |
| 18 |
#include "Galeri_Maps.h" |
| 19 |
#include "Galeri_CrsMatrices.h" |
| 20 |
#include "Galeri_Utils.h" |
| 21 |
|
| 22 |
// MueLu |
| 23 |
#include "MueLu.hpp" |
| 24 |
#include <MueLu_Level.hpp> |
| 25 |
#include <MueLu_BaseClass.hpp> |
| 26 |
#include <MueLu_Utilities.hpp> |
| 27 |
#include <MueLu_MutuallyExclusiveTime.hpp> |
| 28 |
|
| 29 |
// Belos |
| 30 |
#include <BelosConfigDefs.hpp> |
| 31 |
#include <BelosLinearProblem.hpp> |
| 32 |
#include <BelosBlockGmresSolMgr.hpp> |
| 33 |
#include <BelosXpetraAdapter.hpp> |
| 34 |
#include <BelosMueLuAdapter.hpp> |
| 35 |
|
| 36 |
#ifdef HAVE_MPI |
| 37 |
#include "Epetra_MpiComm.h" |
| 38 |
#include "mpi.h" |
| 39 |
#else |
| 40 |
#include "Epetra_SerialComm.h" |
| 41 |
#endif |
| 42 |
#include "Epetra_Map.h" |
| 43 |
#include "Epetra_Vector.h" |
| 44 |
#include "Epetra_CrsMatrix.h" |
| 45 |
#include "Epetra_LinearProblem.h" |
| 46 |
#include "Teuchos_ParameterList.hpp" |
| 47 |
|
| 48 |
using namespace Galeri; |
| 49 |
|
| 50 |
// =========== // |
| 51 |
// main driver // |
| 52 |
// =========== // |
| 53 |
|
| 54 |
int main(int argc, char* argv[]) { |
| 55 |
#ifdef HAVE_MPI |
| 56 |
MPI_Init(&argc, &argv); |
| 57 |
Epetra_MpiComm Comm(MPI_COMM_WORLD); |
| 58 |
#else |
| 59 |
Epetra_SerialComm Comm; |
| 60 |
#endif |
| 61 |
|
| 62 |
// Here we create the linear problem |
| 63 |
// |
| 64 |
// Matrix * LHS = RHS |
| 65 |
// |
| 66 |
// with Matrix arising from a 5-point formula discretization. |
| 67 |
|
| 68 |
Epetra_Map* Map = 0; |
| 69 |
Epetra_RowMatrix* Matrix = 0; |
| 70 |
|
| 71 |
Teuchos::ParameterList GaleriList; |
| 72 |
// dimension of the problem is nx x ny |
| 73 |
GaleriList.set("nx", 10 * Comm.NumProc()); |
| 74 |
GaleriList.set("ny", 10); |
| 75 |
// total number of processors is mx x my |
| 76 |
GaleriList.set("mx", Comm.NumProc()); |
| 77 |
GaleriList.set("my", 1); |
| 78 |
|
| 79 |
try { |
| 80 |
Map = CreateMap("Cartesian2D", Comm, GaleriList); |
| 81 |
Matrix = CreateCrsMatrix("Laplace2D", Map, GaleriList); |
| 82 |
Epetra_Vector ExactSolution(*Map); |
| 83 |
ExactSolution.Random(); |
| 84 |
Epetra_Vector LHS(*Map); |
| 85 |
LHS.PutScalar(0.0); |
| 86 |
Epetra_Vector RHS(*Map); |
| 87 |
|
| 88 |
Matrix->Multiply(false, ExactSolution, RHS); |
| 89 |
|
| 90 |
Epetra_LinearProblem Problem(Matrix, &LHS, &RHS); |
| 91 |
|
| 92 |
// at this point any object that understand Epetra_LinearProblem can be |
| 93 |
// used, for example AztecOO, Amesos. IFPACK and ML can be used to define a |
| 94 |
// preconditioner for Matrix. Here we use a simple solver, based on |
| 95 |
// LAPACK, that is meant for simple testing only. |
| 96 |
|
| 97 |
Solve(Problem); |
| 98 |
|
| 99 |
// and we compute the norm of the true residual. |
| 100 |
double ResidualNorm = ComputeNorm(Matrix, &LHS, &RHS); |
| 101 |
|
| 102 |
if (Comm.MyPID() == 0) |
| 103 |
cout << ResidualNorm << endl; |
| 104 |
|
| 105 |
delete Map; |
| 106 |
delete Matrix; |
| 107 |
} catch (Galeri::Exception& rhs) { |
| 108 |
if (Comm.MyPID() == 0) |
| 109 |
rhs.Print(); |
| 110 |
exit(EXIT_FAILURE); |
| 111 |
} |
| 112 |
|
| 113 |
#ifdef HAVE_MPI |
| 114 |
MPI_Finalize(); |
| 115 |
#endif |
| 116 |
|
| 117 |
return (EXIT_SUCCESS); |
| 118 |
} |