#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_LinearProblem.h"
#include "Galeri_Maps.h"
#include "Galeri_CrsMatrices.h"
#include "Teuchos_ParameterList.hpp"
#include "Teuchos_RefCountPtr.hpp"
#include "AztecOO.h"
#include "Ifpack.h"
#include "Ifpack_AdditiveSchwarz.h"
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
  MPI_Init(&argc,&argv);
#else
#endif
  Teuchos::ParameterList GaleriList;
  
  int nx = 30;
  GaleriList.set("n", nx * nx);
  GaleriList.set("nx", nx);
  GaleriList.set("ny", nx);
  Teuchos::RefCountPtr<Epetra_Map> Map = Teuchos::rcp( Galeri::CreateMap("Linear", Comm, GaleriList) );
  Teuchos::RefCountPtr<Epetra_RowMatrix> A = Teuchos::rcp( Galeri::CreateCrsMatrix("Laplace2D", &*Map, GaleriList) );
  
  
  
  Teuchos::ParameterList List;
  
  
  
  
  std::string PrecType = "ILU"; 
  int OverlapLevel = 1; 
                        
  Teuchos::RefCountPtr<Ifpack_Preconditioner> Prec = Teuchos::rcp( Factory.
Create(PrecType, &*A, OverlapLevel) );
  assert(Prec != Teuchos::null);
  
  List.set("fact: drop tolerance", 1e-9);
  List.set("fact: level-of-fill", 1);
  
  
  
  List.set("schwarz: combine mode", "Add");
  
  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);
  std::cout << *Prec;
#ifdef HAVE_MPI
  MPI_Finalize() ;
#endif
  return(EXIT_SUCCESS);
}