// -------------------------------------------------------------------------------------- int main(int argc, char *argv[]) { #include <MueLu_UseShortNames.hpp> using Teuchos::RCP; using Teuchos::rcp; using Teuchos::TimeMonitor; Teuchos::GlobalMPISession mpiSession(&argc, &argv, NULL); bool success = false; bool verbose = true; try { RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); RCP<Teuchos::FancyOStream> fancy = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); Teuchos::FancyOStream& out = *fancy; typedef Teuchos::ScalarTraits<SC> STS; // ========================================================================= // Parameters initialization // ========================================================================= Teuchos::CommandLineProcessor clp(false); GO nx = 100, ny = 100, nz = 100; Galeri::Xpetra::Parameters<GO> galeriParameters(clp, nx, ny, nz, "Laplace2D"); // manage parameters of the test case Xpetra::Parameters xpetraParameters(clp); // manage parameters of Xpetra switch (clp.parse(argc, argv)) { case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS; break; case Teuchos::CommandLineProcessor::PARSE_ERROR: case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE; break; case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break; } Xpetra::UnderlyingLib lib = xpetraParameters.GetLib(); ParameterList galeriList = galeriParameters.GetParameterList(); out << thickSeparator << std::endl << xpetraParameters << galeriParameters; // ========================================================================= // Problem construction // ========================================================================= RCP<const Map> map; RCP<Matrix> A,P,R, Ac; RCP<MultiVector> nullspace; std::string matrixType = galeriParameters.GetMatrixType(); MueLuExamples::generate_user_matrix_and_nullspace(matrixType,lib,galeriList,comm,A,nullspace); map=A->getRowMap(); // ========================================================================= // Setups and solves // ========================================================================= RCP<Vector> X = VectorFactory::Build(map); RCP<Vector> B = VectorFactory::Build(map); B->setSeed(846930886); B->randomize(); RCP<TimeMonitor> tm; #ifdef HAVE_MUELU_BELOS // Belos Options RCP<Teuchos::ParameterList> SList = rcp(new Teuchos::ParameterList ); SList->set("Verbosity",Belos::Errors + Belos::Warnings + Belos::StatusTestDetails); SList->set("Output Frequency",10); SList->set("Output Style",Belos::Brief); SList->set("Maximum Iterations",200); SList->set("Convergence Tolerance",1e-10); #endif // ========================================================================= // Solve #1 (standard MueLu) // ========================================================================= out << thickSeparator << std::endl; out << prefSeparator << " Solve 1: Standard "<< prefSeparator <<std::endl; { // Use an ML-style parameter list for variety Teuchos::ParameterList MLList; MLList.set("ML output", 10); MLList.set("coarse: type","Amesos-Superlu"); #ifdef HAVE_AMESOS2_KLU2 MLList.set("coarse: type","Amesos-KLU"); #endif MLParameterListInterpreter mueLuFactory(MLList); RCP<Hierarchy> H = mueLuFactory.CreateHierarchy(); Teuchos::RCP<FactoryManagerBase> LevelFactory = mueLuFactory.GetFactoryManager(1); H->setlib(lib); H->AddNewLevel(); H->GetLevel(1)->Keep("Nullspace",LevelFactory->GetFactory("Nullspace").get()); H->GetLevel(0)->Set("A", A); mueLuFactory.SetupHierarchy(*H); #ifdef HAVE_MUELU_BELOS // Solve MueLuExamples::solve_system_hierarchy(lib,A,X,B,H,SList); #endif // Extract R,P & Ac for LevelWrap Usage H->GetLevel(1)->Get("R",R); H->GetLevel(1)->Get("P",P); H->GetLevel(1)->Get("A",Ac); nullspace = H->GetLevel(1)->Get<RCP<MultiVector> >("Nullspace",LevelFactory->GetFactory("Nullspace").get()); } out << thickSeparator << std::endl; // ========================================================================= // Solve #2 (level wrap, the long way, using pre-done Ac) // ========================================================================= out << thickSeparator << std::endl; out << prefSeparator << " Solve 2: LevelWrap, Long Way, P, R, Ac "<< prefSeparator <<std::endl; { // Start w/ an ML-style parameter list Teuchos::ParameterList MLList; MLList.set("ML output", 10); MLList.set("coarse: type","Amesos-Superlu"); #ifdef HAVE_AMESOS2_KLU2 MLList.set("coarse: type","Amesos-KLU"); #endif FactoryManager M1; M1.SetFactory("A", MueLu::NoFactory::getRCP()); M1.SetFactory("P", MueLu::NoFactory::getRCP()); M1.SetFactory("R", MueLu::NoFactory::getRCP()); MLParameterListInterpreter mueLuFactory(MLList); mueLuFactory.AddFactoryManager(1, 1, Teuchos::rcpFromRef(M1)); RCP<Hierarchy> H = mueLuFactory.CreateHierarchy(); H->setlib(lib); H->GetLevel(0)->Set("A", A); H->AddNewLevel(); H->GetLevel(1)->Set("R", R); H->GetLevel(1)->Set("P", P); H->GetLevel(1)->Set("A", Ac); H->GetLevel(1)->Set("Nullspace", nullspace); mueLuFactory.SetupHierarchy(*H); #ifdef HAVE_MUELU_BELOS MueLuExamples::solve_system_hierarchy(lib,A,X,B,H,SList); #endif } out << thickSeparator << std::endl; // ========================================================================= // Solve #3 (level wrap, the long way, using P, R and nullspace) // ========================================================================= out << thickSeparator << std::endl; out << prefSeparator << " Solve 3: LevelWrap, Long Way, P, R "<< prefSeparator <<std::endl; { // Start w/ an ML-style parameter list Teuchos::ParameterList MLList; MLList.set("ML output", 10); MLList.set("coarse: type","Amesos-Superlu"); #ifdef HAVE_AMESOS2_KLU2 MLList.set("coarse: type","Amesos-KLU"); #endif FactoryManager M1; M1.SetFactory("P", MueLu::NoFactory::getRCP()); M1.SetFactory("R", MueLu::NoFactory::getRCP()); MLParameterListInterpreter mueLuFactory(MLList); mueLuFactory.AddFactoryManager(1, 1, Teuchos::rcpFromRef(M1)); RCP<Hierarchy> H = mueLuFactory.CreateHierarchy(); H->setlib(lib); H->GetLevel(0)->Set("A", A); H->AddNewLevel(); H->GetLevel(1)->Set("R", R); H->GetLevel(1)->Set("P", P); H->GetLevel(1)->Set("Nullspace", nullspace); mueLuFactory.SetupHierarchy(*H); #ifdef HAVE_MUELU_BELOS MueLuExamples::solve_system_hierarchy(lib,A,X,B,H,SList); #endif } out << thickSeparator << std::endl; // ========================================================================= // Solve #4 (level wrap, the fast way, everything) // ========================================================================= out << thickSeparator << std::endl; out << prefSeparator << " Solve 4: LevelWrap, Fast Way, P, R, Ac "<< prefSeparator <<std::endl; { Teuchos::ParameterList MueLuList, level1; level1.set("A",Ac); level1.set("R",R); level1.set("P",P); level1.set("Nullspace",nullspace); MueLuList.set("level 1",level1); MueLuList.set("verbosity","high"); MueLuList.set("coarse: max size",100); MueLuList.set("max levels",4); #ifdef HAVE_MUELU_BELOS MueLuExamples::solve_system_list(lib,A,X,B,MueLuList,SList); #endif } // ========================================================================= // Solve #5 (level wrap, the fast way, P, R + Nullspace) // ========================================================================= out << thickSeparator << std::endl; out << prefSeparator << " Solve 5: LevelWrap, Fast Way, P, R "<< prefSeparator <<std::endl; { Teuchos::ParameterList MueLuList, level1; level1.set("R",R); level1.set("P",P); level1.set("Nullspace",nullspace); MueLuList.set("level 1",level1); MueLuList.set("verbosity","high"); MueLuList.set("coarse: max size",100); #ifdef HAVE_MUELU_BELOS MueLuExamples::solve_system_list(lib,A,X,B,MueLuList,SList); #endif } // ========================================================================= // Solve #6 (level wrap, the fast way, P only, explicit transpose) // ========================================================================= out << thickSeparator << std::endl; out << prefSeparator << " Solve 6: LevelWrap, Fast Way, P only, explicit transpose "<< prefSeparator <<std::endl; { Teuchos::ParameterList MueLuList, level1; level1.set("P",P); level1.set("Nullspace",nullspace); MueLuList.set("level 1",level1); MueLuList.set("verbosity","high"); MueLuList.set("coarse: max size",100); MueLuList.set("transpose: use implicit",false); MueLuList.set("max levels",4); #ifdef HAVE_MUELU_BELOS MueLuExamples::solve_system_list(lib,A,X,B,MueLuList,SList); #endif } // ========================================================================= // Solve #7 (level wrap, the fast way, P only, implicit transpose) // ========================================================================= out << thickSeparator << std::endl; out << prefSeparator << " Solve 7: LevelWrap, Fast Way, P only, implicit transpose "<< prefSeparator <<std::endl; { Teuchos::ParameterList MueLuList, level1; level1.set("P",P); level1.set("Nullspace",nullspace); MueLuList.set("level 1",level1); MueLuList.set("verbosity","high"); MueLuList.set("coarse: max size",100); MueLuList.set("transpose: use implicit",true); MueLuList.set("max levels",2); #ifdef HAVE_MUELU_BELOS MueLuExamples::solve_system_list(lib,A,X,B,MueLuList,SList); #endif } success = true; } TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success); return ( success ? EXIT_SUCCESS : EXIT_FAILURE ); }