/* ******************************************************************** */ /* See the file COPYRIGHT for a complete copyright notice, contact */ /* person and disclaimer. */ /* ******************************************************************** */ // Current revision: $Revision$ // Branch: $Branch$ // Last modified: $Date$ // Modified by: $Author$ #include "ml_include.h" #if defined(HAVE_ML_EPETRA) && defined(HAVE_ML_TEUCHOS) && defined(HAVE_ML_GALERI) && defined(HAVE_ML_AZTECOO) #ifdef HAVE_MPI #include "mpi.h" #include "Epetra_MpiComm.h" #else #include "Epetra_SerialComm.h" #endif #include "Epetra_Map.h" #include "Epetra_Vector.h" #include "Epetra_CrsMatrix.h" #include "Epetra_LinearProblem.h" #include "Galeri_Maps.h" #include "Galeri_CrsMatrices.h" #include "AztecOO.h" #include "ml_MultiLevelPreconditioner.h" using namespace Teuchos; using namespace Galeri; // *********************************************************************** int main(int argc, char *argv[]) { #ifdef HAVE_MPI MPI_Init(&argc,&argv); Epetra_MpiComm Comm(MPI_COMM_WORLD); #else Epetra_SerialComm Comm; #endif int nx = 500, ny = 500; ParameterList GaleriList; GaleriList.set("nx", nx); GaleriList.set("ny", ny); GaleriList.set("mx", 1); GaleriList.set("my", Comm.NumProc()); Epetra_Map* Map = CreateMap("Cartesian2D", Comm, GaleriList); Epetra_CrsMatrix* A = CreateCrsMatrix("Star2D", Map, GaleriList); Epetra_Vector LHS(*Map); LHS.Random(); Epetra_Vector RHS(*Map); RHS.PutScalar(0.0); Epetra_LinearProblem Problem(A, &LHS, &RHS); AztecOO solver(Problem); ParameterList MLList; ML_Epetra::SetDefaults("SA",MLList); MLList.set("ML output", 10); MLList.set("max levels",5); MLList.set("increasing or decreasing","increasing"); MLList.set("aggregation: type", "METIS"); MLList.set("aggregation: nodes per aggregate", 100); MLList.set("aggregation: smoothing sweeps", 5); MLList.set("smoother: type","Chebyshev"); MLList.set("smoother: sweeps", 5); MLList.set("smoother: pre or post", "both"); #ifdef HAVE_ML_AMESOS MLList.set("coarse: type","Amesos-KLU"); #else MLList.set("coarse: type","Chebyshev"); #endif ML_Epetra::MultiLevelPreconditioner* MLPrec = new ML_Epetra::MultiLevelPreconditioner(*A, MLList); MLPrec->PrintUnused(0); MLPrec->PrintStencil2D(nx,ny); solver.SetPrecOperator(MLPrec); solver.SetAztecOption(AZ_solver, AZ_cg); solver.SetAztecOption(AZ_output, 1); solver.Iterate(500, 1e-12); delete MLPrec; double residual; LHS.Norm2(&residual); if( Comm.MyPID()==0 ) { cout << "||b-Ax||_2 = " << residual << endl; } // for testing purposes if (residual > 1e-5) exit(EXIT_FAILURE); delete A; delete Map; #ifdef HAVE_MPI MPI_Finalize(); #endif return(EXIT_SUCCESS); } #else #include #include #ifdef HAVE_MPI #include "mpi.h" #endif int main(int argc, char *argv[]) { #ifdef HAVE_MPI MPI_Init(&argc,&argv); #endif puts("Please configure ML with:"); puts("--enable-epetra"); puts("--enable-teuchos"); puts("--enable-aztecoo"); puts("--enable-galeri"); #ifdef HAVE_MPI MPI_Finalize(); #endif return(EXIT_SUCCESS); } #endif