#include "Ifpack_ConfigDefs.h"
#ifdef HAVE_MPI
#include "Epetra_MpiComm.h"
#else
#include "Epetra_SerialComm.h"
#endif
#include "Epetra_CrsMatrix.h"
#include "Epetra_MultiVector.h"
#include "Epetra_Map.h"
#include "Epetra_BlockMap.h"
#include "Epetra_LinearProblem.h"
#include "Galeri_Maps.h"
#include "Galeri_CrsMatrices.h"
#include "Teuchos_ParameterList.hpp"
#include "Teuchos_RefCountPtr.hpp"
#include "AztecOO.h"
#include "Ifpack.h"
int main(int argc, char *argv[])
{
  
#ifdef HAVE_MPI
  MPI_Init(&argc,&argv);
#else
#endif
  Teuchos::ParameterList GaleriList;
  
  int nx = 30; 
  GaleriList.set("nx", nx);
  GaleriList.set(
"ny", nx * Comm.
NumProc());
  GaleriList.set("mx", 1);
  GaleriList.set(
"my", Comm.
NumProc());
  Teuchos::RefCountPtr<Epetra_Map> Map = Teuchos::rcp( Galeri::CreateMap("Cartesian2D", Comm, GaleriList) );
  Teuchos::RefCountPtr<Epetra_RowMatrix> A = Teuchos::rcp( Galeri::CreateCrsMatrix("Laplace2D", &*Map, GaleriList) );
  
  
  
  Teuchos::ParameterList List;
  
  
  
  
  std::string PrecType = "Amesos";
  int OverlapLevel = 2; 
                        
  Teuchos::RefCountPtr<Ifpack_Preconditioner> Prec = Teuchos::rcp( Factory.
Create(PrecType, &*A, OverlapLevel) );
  assert(Prec != Teuchos::null);
  
  
  
  
  
  List.set("amesos: solver type", "Amesos_Klu");
  
  IFPACK_CHK_ERR(Prec->SetParameters(List));
  
  
  
  IFPACK_CHK_ERR(Prec->Initialize());
  
  
  
  IFPACK_CHK_ERR(Prec->Compute());
  
  
  
  
  
  
  
  LHS.PutScalar(1.0);
  
  A->Apply(LHS,RHS);
  
  RHS.Random();
  
  
  AztecOO Solver(Problem);
  
  Solver.SetAztecOption(AZ_solver,AZ_gmres);
  Solver.SetAztecOption(AZ_output,32);
  
  Solver.SetPrecOperator(&*Prec);
  
  
  
  Solver.Iterate(1550,1e-8);
#ifdef HAVE_MPI
  MPI_Finalize() ; 
#endif
    return(EXIT_SUCCESS);
}