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(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 ); }