Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Test_KLU/cxx_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 
19 using namespace Galeri;
20 
21 //============ //
22 // main driver //
23 //============ //
24 
25 int main(int argc, char *argv[])
26 {
27 #ifdef HAVE_MPI
28  MPI_Init(&argc, &argv);
29  Epetra_MpiComm Comm(MPI_COMM_WORLD);
30 #else
31  Epetra_SerialComm Comm;
32 #endif
33 
34  Teuchos::ParameterList GaleriList;
35  GaleriList.set("n", 5);
36 
37  Epetra_Map* Map = CreateMap("Random", Comm, GaleriList);
38  Epetra_CrsMatrix* Matrix = CreateCrsMatrix("Minij", Map, GaleriList);
39 
40  int NumVectors = 2;
41  Amesos_TestRowMatrix A(Matrix);
42  Epetra_MultiVector x(*Map,NumVectors);
43  Epetra_MultiVector x_exact(*Map,NumVectors);
44  Epetra_MultiVector b(*Map,NumVectors);
45  x_exact.Random();
46  A.Multiply(false,x_exact,b);
47 
48  // =========== //
49  // AMESOS PART //
50  // =========== //
51 
52  Epetra_LinearProblem Problem(&A, &x, &b);
53  Amesos_Klu Solver(Problem);
54 
57  AMESOS_CHK_ERR(Solver.Solve());
58 
59  double norm = ComputeNorm(Matrix, &x_exact, &b);
60  if (Comm.MyPID() == 0)
61  std::cout << "norm = " << norm << std::endl;
62 
63  if (norm > 1e-5)
64  exit(EXIT_FAILURE);
65 
66 #ifdef HAVE_MPI
67  MPI_Finalize();
68 #endif
69 
70  return(EXIT_SUCCESS);
71 }
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)
Amesos_TestRowMatrix: a class to test Epetra_RowMatrix based codes.
int MyPID() const
virtual int Multiply(bool TransA, const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_RowMatrix multiplied by a Epetra_MultiVector X in Y.
#define AMESOS_CHK_ERR(a)
int main(int argc, char *argv[])
int NumericFactorization()
Performs NumericFactorization on the matrix A.
Definition: Amesos_Klu.cpp:681
int CreateCrsMatrix(const char *in_filename, const Epetra_Comm &Comm, Epetra_Map *&readMap, const bool transpose, const bool distribute, bool &symmetric, Epetra_CrsMatrix *&Matrix)
Definition: TestOptions.cpp:81
int SymbolicFactorization()
Performs SymbolicFactorization on the matrix A.
Definition: Amesos_Klu.cpp:617