Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
15 #include "Galeri_Maps.h"
16 #include "Galeri_CrsMatrices.h"
17 #include "Galeri_Utils.h"
18 
20 
21 #include <vector>
22 
23 using namespace Galeri;
24 
25 //============ //
26 // main driver //
27 //============ //
28 
29 
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 
42 {
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 
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 
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 }
Amesos_Klu: A serial, unblocked code ideal for getting started and for very sparse matrices...
Definition: Amesos_Klu.h:111
int Solve()
Solves A X = B (or AT x = B)
Definition: Amesos_Klu.cpp:729
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Teuchos::RCP< Epetra_Map > buildMap(Epetra_Comm &Comm)
virtual int InsertGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
int MyPID() const
virtual int MyPID() const =0
int FillComplete(bool OptimizeDataStorage=true)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define AMESOS_CHK_ERR(a)
int GID(int LID) const
int main(int argc, char *argv[])
Teuchos::RCP< Epetra_CrsMatrix > buildMatrix(Epetra_Map &map)
int SetParameters(Teuchos::ParameterList &ParameterList)
Updates internal variables.
Definition: Amesos_Klu.cpp:449