Debian Codegraph @

packages/ml/test/METISCoarsening/cxx_main.cpp

raw
1 /* ******************************************************************** */
2 /* See the file COPYRIGHT for a complete copyright notice, contact */
3 /* person and disclaimer. */
4 /* ******************************************************************** */
5
6 // Current revision: $Revision$
7 // Branch: $Branch$
8 // Last modified: $Date$
9 // Modified by: $Author$
10
11 #include "ml_include.h"
12
13 #if defined(HAVE_ML_EPETRA) && defined(HAVE_ML_TEUCHOS) && defined(HAVE_ML_GALERI) && defined(HAVE_ML_AZTECOO)
14
15 #ifdef HAVE_MPI
16 #include "mpi.h"
17 #include "Epetra_MpiComm.h"
18 #else
19 #include "Epetra_SerialComm.h"
20 #endif
21 #include "Epetra_Map.h"
22 #include "Epetra_Vector.h"
23 #include "Epetra_CrsMatrix.h"
24 #include "Epetra_LinearProblem.h"
25 #include "Galeri_Maps.h"
26 #include "Galeri_CrsMatrices.h"
27 #include "AztecOO.h"
28 #include "ml_MultiLevelPreconditioner.h"
29
30 using namespace Teuchos;
31 using namespace Galeri;
32
33 // ***********************************************************************
34
35 int main(int argc, char *argv[])
36 {
37
38 #ifdef HAVE_MPI
39 MPI_Init(&argc,&argv);
40 Epetra_MpiComm Comm(MPI_COMM_WORLD);
41 #else
42 Epetra_SerialComm Comm;
43 #endif
44
45 int nx = 500, ny = 500;
46
47 ParameterList GaleriList;
48 GaleriList.set("nx", nx);
49 GaleriList.set("ny", ny);
50 GaleriList.set("mx", 1);
51 GaleriList.set("my", Comm.NumProc());
52
53 Epetra_Map* Map = CreateMap("Cartesian2D", Comm, GaleriList);
54 Epetra_CrsMatrix* A = CreateCrsMatrix("Star2D", Map, GaleriList);
55
56 Epetra_Vector LHS(*Map); LHS.Random();
57 Epetra_Vector RHS(*Map); RHS.PutScalar(0.0);
58
59 Epetra_LinearProblem Problem(A, &LHS, &RHS);
60
61 AztecOO solver(Problem);
62
63 ParameterList MLList;
64 ML_Epetra::SetDefaults("SA",MLList);
65
66 MLList.set("ML output", 10);
67 MLList.set("max levels",5);
68 MLList.set("increasing or decreasing","increasing");
69
70 MLList.set("aggregation: type", "METIS");
71 MLList.set("aggregation: nodes per aggregate", 100);
72 MLList.set("aggregation: smoothing sweeps", 5);
73
74 MLList.set("smoother: type","Chebyshev");
75 MLList.set("smoother: sweeps", 5);
76 MLList.set("smoother: pre or post", "both");
77
78 #ifdef HAVE_ML_AMESOS
79 MLList.set("coarse: type","Amesos-KLU");
80 #else
81 MLList.set("coarse: type","Chebyshev");
82 #endif
83
84 ML_Epetra::MultiLevelPreconditioner* MLPrec =
85 new ML_Epetra::MultiLevelPreconditioner(*A, MLList);
86
87 MLPrec->PrintUnused(0);
88 MLPrec->PrintStencil2D(nx,ny);
89
90 solver.SetPrecOperator(MLPrec);
91 solver.SetAztecOption(AZ_solver, AZ_cg);
92 solver.SetAztecOption(AZ_output, 1);
93 solver.Iterate(500, 1e-12);
94
95 delete MLPrec;
96
97 double residual;
98 LHS.Norm2(&residual);
99
100 if( Comm.MyPID()==0 ) {
101 cout << "||b-Ax||_2 = " << residual << endl;
102 }
103
104 // for testing purposes
105 if (residual > 1e-5)
106 exit(EXIT_FAILURE);
107
108 delete A;
109 delete Map;
110
111 #ifdef HAVE_MPI
112 MPI_Finalize();
113 #endif
114
115 return(EXIT_SUCCESS);
116 }
117
118 #else
119
120 #include <stdlib.h>
121 #include <stdio.h>
122 #ifdef HAVE_MPI
123 #include "mpi.h"
124 #endif
125
126 int main(int argc, char *argv[])
127 {
128 #ifdef HAVE_MPI
129 MPI_Init(&argc,&argv);
130 #endif
131
132 puts("Please configure ML with:");
133 puts("--enable-epetra");
134 puts("--enable-teuchos");
135 puts("--enable-aztecoo");
136 puts("--enable-galeri");
137
138 #ifdef HAVE_MPI
139 MPI_Finalize();
140 #endif
141
142 return(EXIT_SUCCESS);
143 }
144
145 #endif