void AdaptiveSaMLParameterListInterpreter<Scalar, LocalOrdinal, GlobalOrdinal, Node>::SetupInitHierarchy(Hierarchy & H) const { TEUCHOS_TEST_FOR_EXCEPTION(!H.GetLevel(0)->IsAvailable("A"), Exceptions::RuntimeError, "No fine level operator"); RCP<Level> l = H.GetLevel(0); RCP<Operator> Op = l->Get<RCP<Operator> >("A"); SetupOperator(*Op); // use overloaded SetupMatrix routine this->SetupExtra(H); // Setup Hierarchy H.SetMaxCoarseSize(this->maxCoarseSize_); // TODO int levelID = 0; int lastLevelID = this->numDesiredLevel_ - 1; bool isLastLevel = false; while(!isLastLevel) { bool r = H.Setup(levelID, InitLvlMngr(levelID-1, lastLevelID), InitLvlMngr(levelID, lastLevelID), InitLvlMngr(levelID+1, lastLevelID)); isLastLevel = r || (levelID == lastLevelID); levelID++; } }
//! Setup Hierarchy object virtual void SetupHierarchy(Hierarchy& H) const { TEUCHOS_TEST_FOR_EXCEPTION(!H.GetLevel(0)->IsAvailable("A"), Exceptions::RuntimeError, "No fine level operator"); // Setup Matrix // TODO: I should certainly undo this somewhere... RCP<Level> l = H.GetLevel(0); RCP<Matrix> Op = l->Get<RCP<Matrix> >("A"); Xpetra::UnderlyingLib lib = Op->getRowMap()->lib(); H.setlib(lib); SetupMatrix(*Op); SetupExtra(H); // Setup Hierarchy H.SetMaxCoarseSize(maxCoarseSize_); H.SetDefaultVerbLevel(verbosity_); if (graphOutputLevel_ >= 0) H.EnableGraphDumping("dep_graph.dot", graphOutputLevel_); // TODO: coarsestLevelManager H.Clear(); int levelID = 0; int lastLevelID = numDesiredLevel_ - 1; bool isLastLevel = false; while (!isLastLevel) { bool r = H.Setup(levelID, LvlMngr(levelID-1, lastLevelID), LvlMngr(levelID, lastLevelID), LvlMngr(levelID+1, lastLevelID)); isLastLevel = r || (levelID == lastLevelID); levelID++; } RCP<Teuchos::FancyOStream> fos = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); fos->setOutputToRootOnly(0); H.print(*fos,verbosity_); // When we reuse hierarchy, it is necessary that we don't // change the number of levels. We also cannot make requests // for coarser levels, because we don't construct all the // data on previous levels. For instance, let's say our first // run constructed three levels. If we try to do requests during // next setup for the fourth level, it would need Aggregates // which we didn't construct for level 3 because we reused P. // To fix this situation, we change the number of desired levels // here. numDesiredLevel_ = levelID; WriteData<Matrix>(H, matricesToPrint_, "A"); WriteData<Matrix>(H, prolongatorsToPrint_, "P"); WriteData<Matrix>(H, restrictorsToPrint_, "R"); } //SetupHierarchy
//! Setup Hierarchy object virtual void SetupHierarchy(Hierarchy & H) const { TEUCHOS_TEST_FOR_EXCEPTION(!H.GetLevel(0)->IsAvailable("A"), Exceptions::RuntimeError, "No fine level operator"); // Setup Matrix // TODO: I should certainly undo this somewhere... RCP<Level> l = H.GetLevel(0); RCP<Matrix> Op = l->Get<RCP<Matrix> >("A"); SetupMatrix(*Op); SetupExtra(H); // Setup Hierarchy H.SetMaxCoarseSize(maxCoarseSize_); H.SetDefaultVerbLevel(verbosity_); if (graphOutputLevel_ >= 0) H.EnableGraphDumping("dep_graph.dot", graphOutputLevel_); // TODO: coarsestLevelManager int levelID = 0; int lastLevelID = numDesiredLevel_ - 1; bool isLastLevel = false; while (!isLastLevel) { bool r = H.Setup(levelID, LvlMngr(levelID-1, lastLevelID), LvlMngr(levelID, lastLevelID), LvlMngr(levelID+1, lastLevelID)); isLastLevel = r || (levelID == lastLevelID); levelID++; } WriteData<Matrix>(H, matricesToPrint_, "A"); WriteData<Matrix>(H, prolongatorsToPrint_, "P"); WriteData<Matrix>(H, restrictorsToPrint_, "R"); } //SetupHierarchy
int main_(Teuchos::CommandLineProcessor &clp, Xpetra::UnderlyingLib lib, int argc, char *argv[]) { #include <MueLu_UseShortNames.hpp> using Teuchos::RCP; using Teuchos::rcp; // // MPI initialization // Teuchos::oblackholestream blackhole; bool success = false; bool verbose = true; try { RCP< const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); // // Process command line arguments // Galeri::Xpetra::Parameters<GO> matrixParameters(clp, 81); // 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; case Teuchos::CommandLineProcessor::PARSE_ERROR: case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE; case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break; default:; } if (comm->getRank() == 0) std::cout << xpetraParameters << matrixParameters; // // Setup test case (Ax = b) // // Distribution RCP<const Map> map = MapFactory::Build(lib, matrixParameters.GetNumGlobalElements(), 0, comm); // Matrix RCP<Galeri::Xpetra::Problem<Map,CrsMatrixWrap,MultiVector> > Pr = Galeri::Xpetra::BuildProblem<SC, LO, GO, Map, CrsMatrixWrap, MultiVector>(matrixParameters.GetMatrixType(), map, matrixParameters.GetParameterList()); RCP<Matrix> A = Pr->BuildMatrix(); // User defined nullspace RCP<MultiVector> nullSpace = VectorFactory::Build(map,1); nullSpace->putScalar((SC) 1.0); // Define B RCP<Vector> X = VectorFactory::Build(map,1); RCP<Vector> B = VectorFactory::Build(map,1); X->setSeed(846930886); X->randomize(); A->apply(*X, *B, Teuchos::NO_TRANS, (SC)1.0, (SC)0.0); // X = 0 X->putScalar((SC) 0.0); // // Create a multigrid configuration // // Transfer operators RCP<TentativePFactory> TentativePFact = rcp( new TentativePFactory() ); RCP<SaPFactory> SaPFact = rcp( new SaPFactory() ); RCP<TransPFactory> RFact = rcp( new TransPFactory()); FactoryManager M; M.SetFactory("Ptent", TentativePFact); M.SetFactory("P", SaPFact); M.SetFactory("R", RFact); M.SetFactory("Smoother", Teuchos::null); //skips smoother setup M.SetFactory("CoarseSolver", Teuchos::null); //skips coarsest solve setup // // Multigrid setup phase // int startLevel = 0; int maxLevels = 10; std::cout << "=============== Setup transfers only ====================" << std::endl; Hierarchy H; H.SetDefaultVerbLevel(MueLu::Medium); RCP<Level> finestLevel = H.GetLevel(); finestLevel->Set("A", A); finestLevel->Set("Nullspace", nullSpace); // Indicate which Hierarchy operators we want to keep H.Keep("P", SaPFact.get()); //SaPFact is the generating factory for P. H.Keep("R", RFact.get()); //RFact is the generating factory for R. H.Keep("Ptent", TentativePFact.get()); //SaPFact is the generating factory for P. H.Setup(M,startLevel,maxLevels); std::cout << "=============== Setup smoothers only ====================" << std::endl; // Create a new A. RCP<Matrix> newA = Pr->BuildMatrix(); finestLevel->Set("A", newA); // Create Gauss-Seidel smoother. std::string ifpackType = "RELAXATION"; Teuchos::ParameterList ifpackList; ifpackList.set("relaxation: sweeps", (LO) 3); ifpackList.set("relaxation: damping factor", (SC) 1.0); RCP<SmootherPrototype> smootherPrototype = rcp(new TrilinosSmoother(ifpackType, ifpackList)); M.SetFactory("Smoother", rcp(new SmootherFactory(smootherPrototype))); // Create coarsest solver. RCP<SmootherPrototype> coarseSolverPrototype = rcp( new DirectSolver() ); RCP<SmootherFactory> coarseSolverFact = rcp( new SmootherFactory(coarseSolverPrototype, Teuchos::null) ); M.SetFactory("CoarseSolver", coarseSolverFact); // Note that we pass the number of levels back in. H.Setup(M,startLevel, H.GetNumLevels()); std::cout << "=============== Solve ====================" << std::endl; // // Solve Ax = B // LO nIts = 9; H.Iterate(*B, *X, nIts); // // Print relative residual norm // typename Teuchos::ScalarTraits<SC>::magnitudeType residualNorms = Utilities::ResidualNorm(*A, *X, *B)[0]; if (comm->getRank() == 0) { std::ios::fmtflags f(std::cout.flags()); std::cout << "||Residual|| = " << std::setiosflags(std::ios::fixed) << std::setprecision(20) << residualNorms << std::endl; std::cout.flags(f); } success = true; } TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success); return ( success ? EXIT_SUCCESS : EXIT_FAILURE ); }
int main(int argc, char *argv[]) { #include "MueLu_UseShortNames.hpp" using Teuchos::RCP; using Teuchos::rcp; using Teuchos::TimeMonitor; Teuchos::oblackholestream blackhole; Teuchos::GlobalMPISession mpiSession(&argc,&argv,&blackhole); bool success = false; bool verbose = true; try { RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); out->setOutputToRootOnly(0); *out << MueLu::MemUtils::PrintMemoryUsage() << std::endl; //#ifndef HAVE_XPETRA_INT_LONG_LONG *out << "Warning: scaling test was not compiled with long long int support" << std::endl; //#endif /**********************************************************************************/ /* SET TEST PARAMETERS */ /**********************************************************************************/ // Note: use --help to list available options. Teuchos::CommandLineProcessor clp(false); 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; } //RCP<TimeMonitor> globalTimeMonitor = rcp (new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: S - Global Time"))); xpetraParameters.check(); Xpetra::UnderlyingLib lib = xpetraParameters.GetLib(); if (comm->getRank() == 0) { std::cout << xpetraParameters; // TODO: print custom parameters // Or use paramList::print()! } /**********************************************************************************/ /* CREATE INITIAL MATRIX */ /**********************************************************************************/ RCP<const Map> bigMap; RCP<const Map> map1; RCP<const Map> map2; GO numElements = 500; GO numElements1 = 400; GO numElements2 = 100; //bigMap = MapFactory::Build(Xpetra::UseEpetra, numElements, 0, comm); // ok this is the problem :-) std::vector<size_t> stridingInfo; stridingInfo.push_back(1); map1 = StridedMapFactory::Build(lib, numElements1, 0, stridingInfo, comm, -1); map2 = StridedMapFactory::Build(lib, numElements2, numElements1, stridingInfo, comm, -1); std::vector<GlobalOrdinal> localGids; // vector with all local GIDs on cur proc Teuchos::ArrayView< const GlobalOrdinal > map1eleList = map1->getNodeElementList(); // append all local gids from map1 and map2 localGids.insert(localGids.end(), map1eleList.begin(), map1eleList.end()); Teuchos::ArrayView< const GlobalOrdinal > map2eleList = map2->getNodeElementList(); localGids.insert(localGids.end(), map2eleList.begin(), map2eleList.end()); Teuchos::ArrayView<GlobalOrdinal> eleList(&localGids[0],localGids.size()); bigMap = StridedMapFactory::Build(lib, numElements, eleList, 0, stridingInfo, comm); // create full big map (concatenation of map1 and map2) std::vector<Teuchos::RCP<const Map> > maps; maps.push_back(map1); maps.push_back(map2); Teuchos::RCP<const Xpetra::MapExtractor<Scalar, LO, GO, Node> > mapExtractor = Xpetra::MapExtractorFactory<Scalar,LO,GO,Node>::Build(bigMap, maps); RCP<CrsMatrixWrap> Op11 = MueLuTests::GenerateProblemMatrix(map1,2,-1,-1); RCP<CrsMatrixWrap> Op22 = MueLuTests::GenerateProblemMatrix(map2,3,-2,-1); /*Op11->describe(*out,Teuchos::VERB_EXTREME); Op22->describe(*out,Teuchos::VERB_EXTREME);*/ // build blocked operator Teuchos::RCP<Xpetra::BlockedCrsMatrix<Scalar,LO,GO,Node> > bOp = Teuchos::rcp(new Xpetra::BlockedCrsMatrix<Scalar,LO,GO>(mapExtractor,mapExtractor,10)); Teuchos::RCP<Xpetra::CrsMatrix<Scalar,LO,GO,Node> > crsMat11 = Op11->getCrsMatrix(); Teuchos::RCP<Xpetra::CrsMatrix<Scalar,LO,GO,Node> > crsMat22 = Op22->getCrsMatrix(); bOp->setMatrix(0,0,crsMat11); bOp->setMatrix(1,1,crsMat22); bOp->fillComplete(); // build hierarchy Hierarchy H; H.SetMaxCoarseSize(50); RCP<Level> levelOne = H.GetLevel(); levelOne->Set("A", Teuchos::rcp_dynamic_cast<Matrix>(bOp)); // set blocked operator RCP<SubBlockAFactory> A11Fact = Teuchos::rcp(new SubBlockAFactory()); A11Fact->SetFactory("A",MueLu::NoFactory::getRCP()); A11Fact->SetParameter("block row",Teuchos::ParameterEntry(0)); A11Fact->SetParameter("block col",Teuchos::ParameterEntry(0)); RCP<SubBlockAFactory> A22Fact = Teuchos::rcp(new SubBlockAFactory()); A22Fact->SetFactory("A",MueLu::NoFactory::getRCP()); A22Fact->SetParameter("block row",Teuchos::ParameterEntry(1)); A22Fact->SetParameter("block col",Teuchos::ParameterEntry(1)); RCP<TentativePFactory> P11Fact = rcp(new TentativePFactory()); RCP<TransPFactory> R11Fact = rcp(new TransPFactory()); RCP<TentativePFactory> P22TentFact = rcp(new TentativePFactory()); RCP<PgPFactory> P22Fact = rcp(new PgPFactory()); RCP<GenericRFactory> R22Fact = rcp(new GenericRFactory()); std::string ifpackType; Teuchos::ParameterList ifpackList; ifpackList.set("relaxation: sweeps", (LO) 5); ifpackList.set("relaxation: damping factor", (SC) 1.0); ifpackType = "RELAXATION"; ifpackList.set("relaxation: type", "Symmetric Gauss-Seidel"); RCP<SmootherPrototype> smoProto11 = rcp( new TrilinosSmoother(ifpackType, ifpackList, 0) ); smoProto11->SetFactory("A", A11Fact); RCP<SmootherPrototype> smoProto22 = rcp( new TrilinosSmoother(ifpackType, ifpackList, 0) ); smoProto22->SetFactory("A", A22Fact); //RCP<SmootherPrototype> smoProto11 = rcp( new DirectSolver("", Teuchos::ParameterList(), A11Fact) ); //RCP<SmootherPrototype> smoProto22 = rcp( new DirectSolver("", Teuchos::ParameterList(), A22Fact) ); RCP<SmootherFactory> Smoo11Fact = rcp( new SmootherFactory(smoProto11) ); RCP<SmootherFactory> Smoo22Fact = rcp( new SmootherFactory(smoProto22) ); RCP<FactoryManager> M11 = rcp(new FactoryManager()); M11->SetFactory("A", A11Fact); M11->SetFactory("P", P11Fact); M11->SetFactory("Ptent", P11Fact); //for Nullspace M11->SetFactory("R", R11Fact); M11->SetFactory("Smoother", Smoo11Fact); M11->SetIgnoreUserData(true); RCP<FactoryManager> M22 = rcp(new FactoryManager()); M22->SetFactory("A", A22Fact); M22->SetFactory("P", P22Fact); M22->SetFactory("R", R22Fact); M22->SetFactory("Ptent", P22TentFact); //for both P22 and Nullspace M22->SetFactory("Smoother", Smoo22Fact); M22->SetIgnoreUserData(true); RCP<BlockedPFactory> PFact = rcp(new BlockedPFactory()); PFact->AddFactoryManager(M11); PFact->AddFactoryManager(M22); RCP<GenericRFactory> RFact = rcp(new GenericRFactory()); RCP<Factory> AcFact = rcp(new BlockedRAPFactory()); // Smoothers RCP<BlockedGaussSeidelSmoother> smootherPrototype = rcp( new BlockedGaussSeidelSmoother() ); smootherPrototype->SetParameter("Sweeps", Teuchos::ParameterEntry(2)); smootherPrototype->SetParameter("Damping factor", Teuchos::ParameterEntry(1.0)); smootherPrototype->AddFactoryManager(M11,0); smootherPrototype->AddFactoryManager(M22,1); RCP<SmootherFactory> smootherFact = rcp( new SmootherFactory(smootherPrototype) ); // Coarse grid correction RCP<BlockedGaussSeidelSmoother> coarseSolverPrototype = rcp( new BlockedGaussSeidelSmoother() ); coarseSolverPrototype->AddFactoryManager(M11,0); coarseSolverPrototype->AddFactoryManager(M22,1); RCP<SmootherFactory> coarseSolverFact = rcp( new SmootherFactory(coarseSolverPrototype, Teuchos::null) ); // main factory manager FactoryManager M; M.SetFactory("A", AcFact); M.SetFactory("P", PFact); M.SetFactory("R", RFact); M.SetFactory("Smoother", smootherFact); // TODO fix me M.SetFactory("CoarseSolver", coarseSolverFact); H.SetVerbLevel(MueLu::Test); H.Setup(M); std::cout << "main AcFact = " << AcFact.get() << std::endl; RCP<Level> l0 = H.GetLevel(0); RCP<Level> l1 = H.GetLevel(1); RCP<Level> l2 = H.GetLevel(2); l0->print(*out,Teuchos::VERB_EXTREME); l1->print(*out,Teuchos::VERB_EXTREME); l2->print(*out,Teuchos::VERB_EXTREME); // Define B RCP<Vector> X = VectorFactory::Build(bigMap,1); RCP<Vector> B = VectorFactory::Build(bigMap,1); X->setSeed(846930886); X->randomize(); bOp->apply(*X, *B, Teuchos::NO_TRANS, (SC)1.0, (SC)0.0); // X = 0 X->putScalar((SC) 0.0); LO nIts = 9; H.Iterate(*B, *X, nIts); success = true; } TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success); return ( success ? EXIT_SUCCESS : EXIT_FAILURE ); }