#include "Amesos_ConfigDefs.h"
#ifdef HAVE_MPI
#include "mpi.h"
#include "Epetra_MpiComm.h"
#else
#include "Epetra_SerialComm.h"
#endif
#include "Amesos.h"
#include "Epetra_CrsMatrix.h"
#include "Epetra_Import.h"
#include "Epetra_Export.h"
#include "Epetra_Map.h"
#include "Epetra_MultiVector.h"
#include "Epetra_Vector.h"
#include "Epetra_LinearProblem.h"
#include "Galeri_ReadHB.h"
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
MPI_Init(&argc, &argv);
#else
#endif
std::string matrix_file;
std::string solver_type;
if (argc > 1)
matrix_file = argv[1];
else
matrix_file = "662_bus.rsa";
if (argc > 2)
solver_type = argv[2];
else
solver_type = "Klu";
std::cout << "Reading matrix `" << matrix_file << "'";
try
{
Galeri::ReadHB(matrix_file.c_str(), Comm, readMap,
readA, readx, readb, readxexact);
}
catch(...)
{
std::cout << "Caught exception, maybe file name is incorrect" << std::endl;
#ifdef HAVE_MPI
MPI_Finalize();
#else
exit(EXIT_SUCCESS);
#endif
}
else
assert(false);
assert (OriginalMap.
SameAs(*readMap));
x.Export(*readx, exporter, Add);
b.Export(*readb, exporter, Add);
xexact.Export(*readxexact, exporter, Add);
A.Export(*readA, exporter, Add);
A.FillComplete();
delete readMap;
delete readA;
delete readx;
delete readb;
delete readxexact;
delete mapPtr;
std::cout << "Calling Amesos..." << std::endl;
Solver = Factory.
Create(solver_type,Problem);
if (Solver == 0) {
std::cerr << "Selected solver (" << solver_type << ") is not available" << std::endl;
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return(EXIT_SUCCESS);
}
double residual;
A.Multiply(false, x, Ax);
Ax.Update(1.0, b, -1.0);
Ax.Norm2(&residual);
std::cout << "After Amesos solution, ||b - A * x||_2 = " << residual << std::endl;
delete Solver;
if (residual > 1e-5)
return(EXIT_FAILURE);
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return(EXIT_SUCCESS);
}