Amesos Package Browser (Single Doxygen Collection)
Development
test
Test_KLU
cxx_memleak_main.cpp
Go to the documentation of this file.
1
#include "
Amesos_ConfigDefs.h
"
2
3
#ifdef HAVE_MPI
4
#include "mpi.h"
5
#include "
Epetra_MpiComm.h
"
6
#else
7
#include "
Epetra_SerialComm.h
"
8
#endif
9
#include "
Epetra_Map.h
"
10
#include "
Epetra_Vector.h
"
11
#include "
Epetra_Util.h
"
12
#include "
Amesos_Klu.h
"
13
#include "
Amesos_TestRowMatrix.h
"
14
#include "
Teuchos_ParameterList.hpp
"
15
#include "Galeri_Maps.h"
16
#include "Galeri_CrsMatrices.h"
17
#include "Galeri_Utils.h"
18
19
#include "
Teuchos_ParameterList.hpp
"
20
21
#include <vector>
22
23
using namespace
Galeri
;
24
25
//============ //
26
// main driver //
27
//============ //
28
29
30
Teuchos::RCP<Epetra_Map>
buildMap
(
Epetra_Comm
&
Comm
)
31
{
32
std::vector<int> vec(4);
33
int
data[] = {0, 1 , 3 , 4};
34
35
for
(
int
i=0;i<4;i++)
36
vec[i] = 6*
Comm
.MyPID()+data[i];
37
38
return
Teuchos::rcp
(
new
Epetra_Map
(-1,4,&vec[0],0,
Comm
));
39
}
40
41
Teuchos::RCP<Epetra_CrsMatrix>
buildMatrix
(
Epetra_Map
& map)
42
{
43
Teuchos::RCP<Epetra_CrsMatrix>
A
=
Teuchos::rcp
(
new
Epetra_CrsMatrix
(
Copy
,map,3));
44
45
int
ind[] = {0,0,0};
46
double
values[] = {-1,2,-1};
47
48
int
* indPtr;
49
double
* valuesPtr;
50
int
entries = 3;
51
52
for
(
int
i=0;i<4;i++) {
53
int
gid = map.
GID
(i);
54
ind[0] = map.
GID
(i-1);
55
ind[1] = map.
GID
(i);
56
ind[2] = map.
GID
(i+1);
57
58
indPtr = ind;
59
valuesPtr = values;
60
entries = 3;
61
if
(i==0) {
62
entries = 2;
63
indPtr = ind+1;
64
valuesPtr = values+1;
65
}
66
else
if
(i==3) {
67
entries = 2;
68
}
69
A
->InsertGlobalValues(gid,entries,valuesPtr,indPtr);
70
}
71
A
->FillComplete();
72
73
return
A
;
74
}
75
76
int
main
(
int
argc,
char
*argv[])
77
{
78
#ifdef HAVE_MPI
79
MPI_Init(&argc, &argv);
80
Epetra_MpiComm
Comm
(MPI_COMM_WORLD);
81
#else
82
Epetra_SerialComm
Comm
;
83
#endif
84
85
Teuchos::ParameterList
GaleriList;
86
87
Teuchos::RCP<Epetra_Map>
Map =
buildMap
(
Comm
);
88
Teuchos::RCP<Epetra_CrsMatrix>
Matrix =
buildMatrix
(*Map);
89
90
int
NumVectors = 2;
91
Epetra_MultiVector
x(*Map,NumVectors);
92
Epetra_MultiVector
x_exact(*Map,NumVectors);
93
Epetra_MultiVector
b(*Map,NumVectors);
94
x_exact.
Random
();
95
Matrix->
Apply
(x_exact,b);
96
97
// =========== //
98
// AMESOS PART //
99
// =========== //
100
101
Epetra_LinearProblem
Problem(&*Matrix, &x, &b);
102
Amesos_Klu
Solver
(Problem);
103
104
Teuchos::ParameterList
List;
105
List.
set
(
"Reindex"
,
true
);
106
107
Solver
.SetParameters(List);
108
109
AMESOS_CHK_ERR
(
Solver
.Solve());
110
AMESOS_CHK_ERR
(
Solver
.Solve());
111
112
double
norm = ComputeNorm(&*Matrix, &x_exact, &b);
113
if
(
Comm
.MyPID() == 0)
114
std::cout <<
"norm = "
<< norm << std::endl;
115
116
if
(norm > 1e-5)
117
exit(EXIT_FAILURE);
118
119
#ifdef HAVE_MPI
120
MPI_Finalize();
121
#endif
122
123
return
(EXIT_SUCCESS);
124
}
Epetra_MultiVector
Amesos_Klu
Amesos_Klu: A serial, unblocked code ideal for getting started and for very sparse matrices...
Definition:
Amesos_Klu.h:111
Epetra_Map
Epetra_MultiVector::Random
int Random()
Teuchos::ParameterList::set
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
buildMap
Teuchos::RCP< Epetra_Map > buildMap(Epetra_Comm &Comm)
Definition:
cxx_memleak_main.cpp:30
Amesos_ConfigDefs.h
Epetra_MpiComm
A
Epetra_SerialComm.h
Amesos_TestRowMatrix.h
Epetra_Comm
Teuchos::rcp
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos_ParameterList.hpp
AMESOS_CHK_ERR
#define AMESOS_CHK_ERR(a)
Definition:
Amesos_ConfigDefs.h:78
Amesos_Klu.h
Solver
Solver
Teuchos::ParameterList
Epetra_SerialComm
main
int main(int argc, char *argv[])
Definition:
cxx_memleak_main.cpp:76
Epetra_MpiComm.h
Teuchos::Comm
Galeri
Epetra_CrsMatrix
Epetra_Map.h
Epetra_Vector.h
Copy
Copy
Teuchos::RCP< Epetra_Map >
Epetra_LinearProblem
Epetra_CrsMatrix::Apply
int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Epetra_Util.h
buildMatrix
Teuchos::RCP< Epetra_CrsMatrix > buildMatrix(Epetra_Map &map)
Definition:
cxx_memleak_main.cpp:41
Epetra_BlockMap::GID
int GID(int LID) const
Generated by
1.8.14