本文整理汇总了C++中Level::GetLevelID方法的典型用法代码示例。如果您正苦于以下问题:C++ Level::GetLevelID方法的具体用法?C++ Level::GetLevelID怎么用?C++ Level::GetLevelID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Level
的用法示例。
在下文中一共展示了Level::GetLevelID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Input
void RigidBodyModeFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::DeclareInput(Level ¤tLevel) const {
if (currentLevel.IsAvailable(nspName_, NoFactory::get()) == false && currentLevel.GetLevelID() == 0) {
Input(currentLevel, "A");
//Input(currentLevel,"Coordinates");
}
if (currentLevel.GetLevelID() !=0) {
currentLevel.DeclareInput("Nullspace", GetFactory(nspName_).get(), this); /* ! "Nullspace" and nspName_ mismatch possible here */
}
}
示例2: m
void TogglePFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(Level& fineLevel, Level &coarseLevel) const {
FactoryMonitor m(*this, "Prolongator toggle", coarseLevel);
std::ostringstream levelstr;
levelstr << coarseLevel.GetLevelID();
typedef typename Teuchos::ScalarTraits<SC>::magnitudeType Magnitude;
TEUCHOS_TEST_FOR_EXCEPTION(nspFacts_.size() != prolongatorFacts_.size(), Exceptions::RuntimeError, "MueLu::TogglePFactory::Build: The number of provided prolongator factories and coarse nullspace factories must be identical.");
TEUCHOS_TEST_FOR_EXCEPTION(nspFacts_.size() != 2, Exceptions::RuntimeError, "MueLu::TogglePFactory::Build: TogglePFactory needs two different transfer operator strategies for toggling."); // TODO adapt this/weaken this as soon as other toggling strategies are introduced.
// decision routine which prolongator factory to be used
int nProlongatorFactory = 0; // default behavior: use first prolongator in list
// extract user parameters
const Teuchos::ParameterList & pL = GetParameterList();
std::string mode = Teuchos::as<std::string>(pL.get<std::string>("toggle: mode"));
int semicoarsen_levels = Teuchos::as<int>(pL.get<int>("semicoarsen: number of levels"));
TEUCHOS_TEST_FOR_EXCEPTION(mode!="semicoarsen", Exceptions::RuntimeError, "MueLu::TogglePFactory::Build: The 'toggle: mode' parameter must be set to 'semicoarsen'. No other mode supported, yet.");
LO NumZDir = -1;
if(fineLevel.IsAvailable("NumZLayers", NoFactory::get())) {
NumZDir = fineLevel.Get<LO>("NumZLayers", NoFactory::get()); //obtain info
GetOStream(Runtime1) << "Number of layers for semicoarsening: " << NumZDir << std::endl;
}
// Make a decision which prolongator to be used.
if(fineLevel.GetLevelID() >= semicoarsen_levels || NumZDir == 1) {
nProlongatorFactory = 1;
} else {
nProlongatorFactory = 0;
}
RCP<Matrix> P = Teuchos::null;
RCP<MultiVector> coarseNullspace = Teuchos::null;
// call Build for selected transfer operator
GetOStream(Runtime0) << "TogglePFactory: call transfer factory: " << (prolongatorFacts_[nProlongatorFactory])->description() << std::endl;
prolongatorFacts_[nProlongatorFactory]->CallBuild(coarseLevel);
P = coarseLevel.Get< RCP<Matrix> >("P", (prolongatorFacts_[nProlongatorFactory]).get());
coarseNullspace = coarseLevel.Get< RCP<MultiVector> >("Nullspace", (nspFacts_[nProlongatorFactory]).get());
// Release dependencies of all prolongator and coarse level null spaces
for(size_t t=0; t<nspFacts_.size(); ++t) {
coarseLevel.Release(*(prolongatorFacts_[t]));
coarseLevel.Release(*(nspFacts_[t]));
}
// store prolongator with this factory identification.
Set(coarseLevel, "P", P);
Set(coarseLevel, "Nullspace", coarseNullspace);
} //Build()
示例3: m
void NullspacePresmoothFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::Build(Level ¤tLevel) const {
FactoryMonitor m(*this, "Nullspace presmooth factory", currentLevel);
RCP<MultiVector> newB;
if (currentLevel.GetLevelID() == 0) {
RCP<Matrix> A = Get< RCP<Matrix> > (currentLevel, "A");
RCP<MultiVector> B = Get< RCP<MultiVector> >(currentLevel, "Nullspace");
newB = MultiVectorFactory::Build(B->getMap(), B->getNumVectors());
Teuchos::ArrayRCP<SC> D = Utils::GetMatrixDiagonal(*A);
SC damping = 4./3;
damping /= Utils::PowerMethod(*A, true, (LO) 10, 1e-4);
A->apply(*B, *newB, Teuchos::NO_TRANS);
size_t numVec = newB->getNumVectors();
LO numElements = newB->getLocalLength();
for (size_t j = 0; j < numVec; j++) {
Teuchos::ArrayRCP<const SC> Bj = B->getData(j);
Teuchos::ArrayRCP<SC> newBj = newB->getDataNonConst(j);
for (LO i = 0; i < numElements; i++)
newBj[i] = Bj[i] - damping*newBj[i]/D[i];
}
} else {
newB = Get< RCP<MultiVector> >(currentLevel, "Nullspace");
}
// provide "Nullspace" variable on current level
Set(currentLevel, "Nullspace", newB);
} // Build
示例4: CallDeclareInput
//!
virtual void CallDeclareInput(Level & requestedLevel) const {
if (requestedLevel.GetPreviousLevel() == Teuchos::null) {
std::ostringstream errStr;
errStr << "LevelID = " << requestedLevel.GetLevelID();
throw Exceptions::DependencyError(errStr.str());
}
DeclareInput(*requestedLevel.GetPreviousLevel(), requestedLevel);
}
示例5: m
void UserAggregationFactory<LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::Build(Level ¤tLevel) const {
FactoryMonitor m(*this, "Build", currentLevel);
const ParameterList & pL = GetParameterList();
RCP< const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
const int myRank = comm->getRank();
std::string fileName = pL.get<std::string>("filePrefix") + toString(currentLevel.GetLevelID()) + "_" + toString(myRank) + "." + pL.get<std::string>("fileExt");
std::ifstream ifs(fileName.c_str());
if (!ifs.good())
throw Exceptions::RuntimeError("Cannot read data from \"" + fileName + "\"");
LO numVertices, numAggregates;
ifs >> numVertices >> numAggregates;
// FIXME: what is the map?
Xpetra::UnderlyingLib lib = Xpetra::UseEpetra;
const int indexBase = 0;
RCP<Map> map = MapFactory::Build(lib, numVertices, indexBase, comm);
RCP<Aggregates> aggregates = rcp(new Aggregates(map));
aggregates->setObjectLabel("User");
aggregates->SetNumAggregates(numAggregates);
Teuchos::ArrayRCP<LO> vertex2AggId = aggregates->GetVertex2AggId()->getDataNonConst(0);
Teuchos::ArrayRCP<LO> procWinner = aggregates->GetProcWinner() ->getDataNonConst(0);
for (LO i = 0; i < numAggregates; i++) {
int aggSize = 0;
ifs >> aggSize;
std::vector<LO> list(aggSize);
for (int k = 0; k < aggSize; k++) {
// FIXME: File contains GIDs, we need LIDs
// for now, works on a single processor
ifs >> list[k];
}
// Mark first node as root node for the aggregate
aggregates->SetIsRoot(list[0]);
// Fill vertex2AggId and procWinner structure with information
for (int k = 0; k < aggSize; k++) {
vertex2AggId[list[k]] = i;
procWinner [list[k]] = myRank;
}
}
// FIXME: do the proper check whether aggregates cross interprocessor boundary
aggregates->AggregatesCrossProcessors(false);
Set(currentLevel, "Aggregates", aggregates);
GetOStream(Statistics0, 0) << aggregates->description() << std::endl;
}
示例6: CallBuild
//!
virtual void CallBuild(Level& requestedLevel) const {
int levelID = requestedLevel.GetLevelID();
#ifdef HAVE_MUELU_DEBUG
// We cannot call Build method twice for the same level, but we can call it multiple times for different levels
TEUCHOS_TEST_FOR_EXCEPTION((multipleCallCheck_ == ENABLED) && (multipleCallCheckGlobal_ == ENABLED) && (lastLevelID_ == levelID),
Exceptions::RuntimeError,
this->ShortClassName() << "::Build() called twice for the same level (levelID=" << levelID
<< "). This is likely due to a configuration error.");
if (multipleCallCheck_ == FIRSTCALL)
multipleCallCheck_ = ENABLED;
lastLevelID_ = levelID;
#endif
TEUCHOS_TEST_FOR_EXCEPTION(requestedLevel.GetPreviousLevel() == Teuchos::null, Exceptions::RuntimeError, "LevelID = " << levelID);
#ifdef HAVE_MUELU_TIMER_SYNCHRONIZATION
RCP<const Teuchos::Comm<int> > comm = requestedLevel.GetComm();
if (comm.is_null()) {
// Some factories are called before we constructed Ac, and therefore,
// before we set the level communicator. For such factories we can get
// the comm from the previous level, as all processes go there
RCP<Level>& prevLevel = requestedLevel.GetPreviousLevel();
if (!prevLevel.is_null())
comm = prevLevel->GetComm();
}
// Synchronization timer
std::string syncTimer = this->ShortClassName() + ": Build sync (level=" + toString(requestedLevel.GetLevelID()) + ")";
if (!comm.is_null()) {
TimeMonitor timer(*this, syncTimer);
comm->barrier();
}
#endif
Build(*requestedLevel.GetPreviousLevel(), requestedLevel);
#ifdef HAVE_MUELU_TIMER_SYNCHRONIZATION
// Synchronization timer
if (!comm.is_null()) {
TimeMonitor timer(*this, syncTimer);
comm->barrier();
}
#endif
GetOStream(Test) << *RemoveFactoriesFromList(GetParameterList()) << std::endl;
}
示例7: m
void SaPFactory_kokkos<Scalar,LocalOrdinal,GlobalOrdinal,Kokkos::Compat::KokkosDeviceWrapperNode<DeviceType>>::BuildP(Level& fineLevel, Level& coarseLevel) const {
FactoryMonitor m(*this, "Prolongator smoothing", coarseLevel);
// Add debugging information
DeviceType::execution_space::print_configuration(GetOStream(Runtime1));
typedef typename Teuchos::ScalarTraits<SC>::magnitudeType Magnitude;
// Get default tentative prolongator factory
// Getting it that way ensure that the same factory instance will be used for both SaPFactory_kokkos and NullspaceFactory.
// -- Warning: Do not use directly initialPFact_. Use initialPFact instead everywhere!
RCP<const FactoryBase> initialPFact = GetFactory("P");
if (initialPFact == Teuchos::null) { initialPFact = coarseLevel.GetFactoryManager()->GetFactory("Ptent"); }
// Level Get
RCP<Matrix> A = Get< RCP<Matrix> >(fineLevel, "A");
RCP<Matrix> Ptent = coarseLevel.Get< RCP<Matrix> >("P", initialPFact.get());
if(restrictionMode_) {
SubFactoryMonitor m2(*this, "Transpose A", coarseLevel);
A = Utilities_kokkos::Transpose(*A, true); // build transpose of A explicitly
}
//Build final prolongator
RCP<Matrix> finalP; // output
// Reuse pattern if available
RCP<ParameterList> APparams = rcp(new ParameterList);
if (coarseLevel.IsAvailable("AP reuse data", this)) {
GetOStream(static_cast<MsgType>(Runtime0 | Test)) << "Reusing previous AP data" << std::endl;
APparams = coarseLevel.Get< RCP<ParameterList> >("AP reuse data", this);
if (APparams->isParameter("graph"))
finalP = APparams->get< RCP<Matrix> >("graph");
}
const ParameterList& pL = GetParameterList();
SC dampingFactor = as<SC>(pL.get<double>("sa: damping factor"));
LO maxEigenIterations = as<LO>(pL.get<int>("sa: eigenvalue estimate num iterations"));
bool estimateMaxEigen = pL.get<bool>("sa: calculate eigenvalue estimate");
if (dampingFactor != Teuchos::ScalarTraits<SC>::zero()) {
SC lambdaMax;
{
SubFactoryMonitor m2(*this, "Eigenvalue estimate", coarseLevel);
lambdaMax = A->GetMaxEigenvalueEstimate();
if (lambdaMax == -Teuchos::ScalarTraits<SC>::one() || estimateMaxEigen) {
GetOStream(Statistics1) << "Calculating max eigenvalue estimate now (max iters = "<< maxEigenIterations << ")" << std::endl;
Magnitude stopTol = 1e-4;
lambdaMax = Utilities_kokkos::PowerMethod(*A, true, maxEigenIterations, stopTol);
A->SetMaxEigenvalueEstimate(lambdaMax);
} else {
GetOStream(Statistics1) << "Using cached max eigenvalue estimate" << std::endl;
}
GetOStream(Statistics0) << "Prolongator damping factor = " << dampingFactor/lambdaMax << " (" << dampingFactor << " / " << lambdaMax << ")" << std::endl;
}
{
SubFactoryMonitor m2(*this, "Fused (I-omega*D^{-1} A)*Ptent", coarseLevel);
RCP<Vector> invDiag = Utilities_kokkos::GetMatrixDiagonalInverse(*A);
SC omega = dampingFactor / lambdaMax;
// finalP = Ptent + (I - \omega D^{-1}A) Ptent
finalP = Xpetra::IteratorOps<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Jacobi(omega, *invDiag, *A, *Ptent, finalP, GetOStream(Statistics2), std::string("MueLu::SaP-") + toString(coarseLevel.GetLevelID()), APparams);
}
} else {
finalP = Ptent;
}
// Level Set
if (!restrictionMode_) {
// prolongation factory is in prolongation mode
Set(coarseLevel, "P", finalP);
// NOTE: EXPERIMENTAL
if (Ptent->IsView("stridedMaps"))
finalP->CreateView("stridedMaps", Ptent);
} else {
// prolongation factory is in restriction mode
RCP<Matrix> R = Utilities_kokkos::Transpose(*finalP, true);
Set(coarseLevel, "R", R);
// NOTE: EXPERIMENTAL
if (Ptent->IsView("stridedMaps"))
R->CreateView("stridedMaps", Ptent, true);
}
if (IsPrint(Statistics1)) {
RCP<ParameterList> params = rcp(new ParameterList());
params->set("printLoadBalancingInfo", true);
params->set("printCommInfo", true);
GetOStream(Statistics1) << PerfUtils::PrintMatrixInfo(*finalP, (!restrictionMode_ ? "P" : "R"), params);
}
} //Build()
示例8: m
void RAPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(Level& fineLevel, Level& coarseLevel) const {
{
FactoryMonitor m(*this, "Computing Ac", coarseLevel);
std::ostringstream levelstr;
levelstr << coarseLevel.GetLevelID();
TEUCHOS_TEST_FOR_EXCEPTION(hasDeclaredInput_==false, Exceptions::RuntimeError,
"MueLu::RAPFactory::Build(): CallDeclareInput has not been called before Build!");
// Set "Keeps" from params
const Teuchos::ParameterList& pL = GetParameterList();
if (pL.get<bool>("Keep AP Pattern"))
coarseLevel.Keep("AP Pattern", this);
if (pL.get<bool>("Keep RAP Pattern"))
coarseLevel.Keep("RAP Pattern", this);
RCP<Matrix> A = Get< RCP<Matrix> >(fineLevel, "A");
RCP<Matrix> P = Get< RCP<Matrix> >(coarseLevel, "P"), AP, Ac;
// Reuse pattern if available (multiple solve)
if (coarseLevel.IsAvailable("AP Pattern", this)) {
GetOStream(Runtime0) << "Ac: Using previous AP pattern" << std::endl;
AP = Get< RCP<Matrix> >(coarseLevel, "AP Pattern");
}
{
SubFactoryMonitor subM(*this, "MxM: A x P", coarseLevel);
AP = Utils::Multiply(*A, false, *P, false, AP, GetOStream(Statistics2),true,true,std::string("MueLu::A*P-")+levelstr.str());
}
if (pL.get<bool>("Keep AP Pattern"))
Set(coarseLevel, "AP Pattern", AP);
// Reuse coarse matrix memory if available (multiple solve)
if (coarseLevel.IsAvailable("RAP Pattern", this)) {
GetOStream(Runtime0) << "Ac: Using previous RAP pattern" << std::endl;
Ac = Get< RCP<Matrix> >(coarseLevel, "RAP Pattern");
// Some eigenvalue may have been cached with the matrix in the previous run.
// As the matrix values will be updated, we need to reset the eigenvalue.
Ac->SetMaxEigenvalueEstimate(-Teuchos::ScalarTraits<SC>::one());
}
// If we do not modify matrix later, allow optimization of storage.
// This is necessary for new faster Epetra MM kernels.
bool doOptimizeStorage = !pL.get<bool>("RepairMainDiagonal");
const bool doTranspose = true;
const bool doFillComplete = true;
if (pL.get<bool>("transpose: use implicit") == true) {
SubFactoryMonitor m2(*this, "MxM: P' x (AP) (implicit)", coarseLevel);
Ac = Utils::Multiply(*P, doTranspose, *AP, !doTranspose, Ac, GetOStream(Statistics2), doFillComplete, doOptimizeStorage,std::string("MueLu::R*(AP)-implicit-")+levelstr.str());
} else {
RCP<Matrix> R = Get< RCP<Matrix> >(coarseLevel, "R");
SubFactoryMonitor m2(*this, "MxM: R x (AP) (explicit)", coarseLevel);
Ac = Utils::Multiply(*R, !doTranspose, *AP, !doTranspose, Ac, GetOStream(Statistics2), doFillComplete, doOptimizeStorage,std::string("MueLu::R*(AP)-explicit-")+levelstr.str());
}
CheckRepairMainDiagonal(Ac);
if (IsPrint(Statistics1)) {
RCP<ParameterList> params = rcp(new ParameterList());;
params->set("printLoadBalancingInfo", true);
params->set("printCommInfo", true);
GetOStream(Statistics1) << PerfUtils::PrintMatrixInfo(*Ac, "Ac", params);
}
Set(coarseLevel, "A", Ac);
if (pL.get<bool>("Keep RAP Pattern"))
Set(coarseLevel, "RAP Pattern", Ac);
}
if (transferFacts_.begin() != transferFacts_.end()) {
SubFactoryMonitor m(*this, "Projections", coarseLevel);
// call Build of all user-given transfer factories
for (std::vector<RCP<const FactoryBase> >::const_iterator it = transferFacts_.begin(); it != transferFacts_.end(); ++it) {
RCP<const FactoryBase> fac = *it;
GetOStream(Runtime0) << "RAPFactory: call transfer factory: " << fac->description() << std::endl;
fac->CallBuild(coarseLevel);
// Coordinates transfer is marginally different from all other operations
// because it is *optional*, and not required. For instance, we may need
// coordinates only on level 4 if we start repartitioning from that level,
// but we don't need them on level 1,2,3. As our current Hierarchy setup
// assumes propagation of dependencies only through three levels, this
// means that we need to rely on other methods to propagate optional data.
//
// The method currently used is through RAP transfer factories, which are
// simply factories which are called at the end of RAP with a single goal:
// transfer some fine data to coarser level. Because these factories are
// kind of outside of the mainline factories, they behave different. In
// particular, we call their Build method explicitly, rather than through
// Get calls. This difference is significant, as the Get call is smart
// enough to know when to release all factory dependencies, and Build is
// dumb. This led to the following CoordinatesTransferFactory sequence:
// 1. Request level 0
// 2. Request level 1
//.........这里部分代码省略.........
示例9: Setup
void IfpackSmoother::Setup(Level ¤tLevel) {
FactoryMonitor m(*this, "Setup Smoother", currentLevel);
if (SmootherPrototype::IsSetup() == true)
GetOStream(Warnings0, 0) << "Warning: MueLu::IfpackSmoother::Setup(): Setup() has already been called";
A_ = Factory::Get< RCP<Matrix> >(currentLevel, "A");
double lambdaMax = -1.0;
if (type_ == "Chebyshev") {
std::string maxEigString = "chebyshev: max eigenvalue";
std::string eigRatioString = "chebyshev: ratio eigenvalue";
try {
lambdaMax = Teuchos::getValue<Scalar>(this->GetParameter(maxEigString));
this->GetOStream(Statistics1, 0) << maxEigString << " (cached with smoother parameter list) = " << lambdaMax << std::endl;
} catch (Teuchos::Exceptions::InvalidParameterName) {
lambdaMax = A_->GetMaxEigenvalueEstimate();
if (lambdaMax != -1.0) {
this->GetOStream(Statistics1, 0) << maxEigString << " (cached with matrix) = " << lambdaMax << std::endl;
this->SetParameter(maxEigString, ParameterEntry(lambdaMax));
}
}
// Calculate the eigenvalue ratio
const Scalar defaultEigRatio = 20;
Scalar ratio = defaultEigRatio;
try {
ratio = Teuchos::getValue<Scalar>(this->GetParameter(eigRatioString));
} catch (Teuchos::Exceptions::InvalidParameterName) {
this->SetParameter(eigRatioString, ParameterEntry(ratio));
}
if (currentLevel.GetLevelID()) {
// Update ratio to be
// ratio = max(number of fine DOFs / number of coarse DOFs, defaultValue)
//
// NOTE: We don't need to request previous level matrix as we know for sure it was constructed
RCP<const Matrix> fineA = currentLevel.GetPreviousLevel()->Get<RCP<Matrix> >("A");
size_t nRowsFine = fineA->getGlobalNumRows();
size_t nRowsCoarse = A_->getGlobalNumRows();
ratio = std::max(ratio, as<Scalar>(nRowsFine)/nRowsCoarse);
this->GetOStream(Statistics1, 0) << eigRatioString << " (computed) = " << ratio << std::endl;
this->SetParameter(eigRatioString, ParameterEntry(ratio));
}
}
RCP<Epetra_CrsMatrix> epA = Utils::Op2NonConstEpetraCrs(A_);
Ifpack factory;
prec_ = rcp(factory.Create(type_, &(*epA), overlap_));
TEUCHOS_TEST_FOR_EXCEPTION(prec_.is_null(), Exceptions::RuntimeError, "Could not create an Ifpack preconditioner with type = \"" << type_ << "\"");
SetPrecParameters();
prec_->Compute();
SmootherPrototype::IsSetup(true);
if (type_ == "Chebyshev" && lambdaMax == -1.0) {
Teuchos::RCP<Ifpack_Chebyshev> chebyPrec = rcp_dynamic_cast<Ifpack_Chebyshev>(prec_);
if (chebyPrec != Teuchos::null) {
lambdaMax = chebyPrec->GetLambdaMax();
A_->SetMaxEigenvalueEstimate(lambdaMax);
this->GetOStream(Statistics1, 0) << "chebyshev: max eigenvalue (calculated by Ifpack)" << " = " << lambdaMax << std::endl;
}
TEUCHOS_TEST_FOR_EXCEPTION(lambdaMax == -1.0, Exceptions::RuntimeError, "MueLu::IfpackSmoother::Setup(): no maximum eigenvalue estimate");
}
this->GetOStream(Statistics0, 0) << description() << std::endl;
}
示例10: m
void SaPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::BuildP(Level &fineLevel, Level &coarseLevel) const {
FactoryMonitor m(*this, "Prolongator smoothing", coarseLevel);
std::ostringstream levelstr;
levelstr << coarseLevel.GetLevelID();
typedef typename Teuchos::ScalarTraits<SC>::magnitudeType Magnitude;
// Get default tentative prolongator factory
// Getting it that way ensure that the same factory instance will be used for both SaPFactory and NullspaceFactory.
// -- Warning: Do not use directly initialPFact_. Use initialPFact instead everywhere!
RCP<const FactoryBase> initialPFact = GetFactory("P");
if (initialPFact == Teuchos::null) { initialPFact = coarseLevel.GetFactoryManager()->GetFactory("Ptent"); }
// Level Get
RCP<Matrix> A = Get< RCP<Matrix> >(fineLevel, "A");
RCP<Matrix> Ptent = coarseLevel.Get< RCP<Matrix> >("P", initialPFact.get());
if(restrictionMode_) {
SubFactoryMonitor m2(*this, "Transpose A", coarseLevel);
A = Utils2::Transpose(*A, true); // build transpose of A explicitely
}
//Build final prolongator
RCP<Matrix> finalP; // output
const ParameterList & pL = GetParameterList();
Scalar dampingFactor = as<Scalar>(pL.get<double>("sa: damping factor"));
LO maxEigenIterations = as<LO>(pL.get<int>("sa: eigenvalue estimate num iterations"));
bool estimateMaxEigen = pL.get<bool>("sa: calculate eigenvalue estimate");
if (dampingFactor != Teuchos::ScalarTraits<Scalar>::zero()) {
Scalar lambdaMax;
{
SubFactoryMonitor m2(*this, "Eigenvalue estimate", coarseLevel);
lambdaMax = A->GetMaxEigenvalueEstimate();
if (lambdaMax == -Teuchos::ScalarTraits<SC>::one() || estimateMaxEigen) {
GetOStream(Statistics1) << "Calculating max eigenvalue estimate now (max iters = "<< maxEigenIterations << ")" << std::endl;
Magnitude stopTol = 1e-4;
lambdaMax = Utils::PowerMethod(*A, true, maxEigenIterations, stopTol);
A->SetMaxEigenvalueEstimate(lambdaMax);
} else {
GetOStream(Statistics1) << "Using cached max eigenvalue estimate" << std::endl;
}
GetOStream(Statistics0) << "Prolongator damping factor = " << dampingFactor/lambdaMax << " (" << dampingFactor << " / " << lambdaMax << ")" << std::endl;
}
{
SubFactoryMonitor m2(*this, "Fused (I-omega*D^{-1} A)*Ptent", coarseLevel);
Teuchos::RCP<Vector> invDiag = Utils::GetMatrixDiagonalInverse(*A);
SC omega = dampingFactor / lambdaMax;
// finalP = Ptent + (I - \omega D^{-1}A) Ptent
finalP = Utils::Jacobi(omega, *invDiag, *A, *Ptent, finalP, GetOStream(Statistics2),std::string("MueLu::SaP-")+levelstr.str());
}
} else {
finalP = Ptent;
}
// Level Set
if (!restrictionMode_) {
// prolongation factory is in prolongation mode
Set(coarseLevel, "P", finalP);
// NOTE: EXPERIMENTAL
if (Ptent->IsView("stridedMaps"))
finalP->CreateView("stridedMaps", Ptent);
} else {
// prolongation factory is in restriction mode
RCP<Matrix> R = Utils2::Transpose(*finalP, true); // use Utils2 -> specialization for double
Set(coarseLevel, "R", R);
// NOTE: EXPERIMENTAL
if (Ptent->IsView("stridedMaps"))
R->CreateView("stridedMaps", Ptent, true);
}
if (IsPrint(Statistics1)) {
RCP<ParameterList> params = rcp(new ParameterList());
params->set("printLoadBalancingInfo", true);
params->set("printCommInfo", true);
GetOStream(Statistics1) << PerfUtils::PrintMatrixInfo(*finalP, (!restrictionMode_ ? "P" : "R"), params);
}
} //Build()
示例11: CallDeclareInput
//!
virtual void CallDeclareInput(Level & requestedLevel) const {
TEUCHOS_TEST_FOR_EXCEPTION(requestedLevel.GetPreviousLevel() == Teuchos::null, Exceptions::RuntimeError, "LevelID = " << requestedLevel.GetLevelID());
DeclareInput(*requestedLevel.GetPreviousLevel(), requestedLevel);
}
示例12: m
void RepartitionFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(Level& currentLevel) const {
FactoryMonitor m(*this, "Build", currentLevel);
const Teuchos::ParameterList & pL = GetParameterList();
// Access parameters here to make sure that we set the parameter entry flag to "used" even in case of short-circuit evaluation.
// TODO (JG): I don't really know if we want to do this.
const int startLevel = pL.get<int> ("repartition: start level");
const LO minRowsPerProcessor = pL.get<LO> ("repartition: min rows per proc");
const double nonzeroImbalance = pL.get<double>("repartition: max imbalance");
const bool remapPartitions = pL.get<bool> ("repartition: remap parts");
// TODO: We only need a CrsGraph. This class does not have to be templated on Scalar types.
RCP<Matrix> A = Get< RCP<Matrix> >(currentLevel, "A");
// ======================================================================================================
// Determine whether partitioning is needed
// ======================================================================================================
// NOTE: most tests include some global communication, which is why we currently only do tests until we make
// a decision on whether to repartition. However, there is value in knowing how "close" we are to having to
// rebalance an operator. So, it would probably be beneficial to do and report *all* tests.
// Test1: skip repartitioning if current level is less than the specified minimum level for repartitioning
if (currentLevel.GetLevelID() < startLevel) {
GetOStream(Statistics0) << "Repartitioning? NO:" <<
"\n current level = " << Teuchos::toString(currentLevel.GetLevelID()) <<
", first level where repartitioning can happen is " + Teuchos::toString(startLevel) << std::endl;
Set<RCP<const Import> >(currentLevel, "Importer", Teuchos::null);
return;
}
RCP<const Map> rowMap = A->getRowMap();
// NOTE: Teuchos::MPIComm::duplicate() calls MPI_Bcast inside, so this is
// a synchronization point. However, as we do MueLu_sumAll afterwards anyway, it
// does not matter.
RCP<const Teuchos::Comm<int> > origComm = rowMap->getComm();
RCP<const Teuchos::Comm<int> > comm = origComm->duplicate();
// Test 2: check whether A is actually distributed, i.e. more than one processor owns part of A
// TODO: this global communication can be avoided if we store the information with the matrix (it is known when matrix is created)
// TODO: further improvements could be achieved when we use subcommunicator for the active set. Then we only need to check its size
{
int numActiveProcesses = 0;
MueLu_sumAll(comm, Teuchos::as<int>((A->getNodeNumRows() > 0) ? 1 : 0), numActiveProcesses);
if (numActiveProcesses == 1) {
GetOStream(Statistics0) << "Repartitioning? NO:" <<
"\n # processes with rows = " << Teuchos::toString(numActiveProcesses) << std::endl;
Set<RCP<const Import> >(currentLevel, "Importer", Teuchos::null);
return;
}
}
bool test3 = false, test4 = false;
std::string msg3, msg4;
// Test3: check whether number of rows on any processor satisfies the minimum number of rows requirement
// NOTE: Test2 ensures that repartitionning is not done when there is only one processor (it may or may not satisfy Test3)
if (minRowsPerProcessor > 0) {
LO numMyRows = Teuchos::as<LO>(A->getNodeNumRows()), minNumRows, LOMAX = Teuchos::OrdinalTraits<LO>::max();
LO haveFewRows = (numMyRows < minRowsPerProcessor ? 1 : 0), numWithFewRows = 0;
MueLu_sumAll(comm, haveFewRows, numWithFewRows);
MueLu_minAll(comm, (numMyRows > 0 ? numMyRows : LOMAX), minNumRows);
// TODO: we could change it to repartition only if the number of processors with numRows < minNumRows is larger than some
// percentage of the total number. This way, we won't repartition if 2 out of 1000 processors don't have enough elements.
// I'm thinking maybe 20% threshold. To implement, simply add " && numWithFewRows < .2*numProcs" to the if statement.
if (numWithFewRows > 0)
test3 = true;
msg3 = "\n min # rows per proc = " + Teuchos::toString(minNumRows) + ", min allowable = " + Teuchos::toString(minRowsPerProcessor);
}
// Test4: check whether the balance in the number of nonzeros per processor is greater than threshold
if (!test3) {
GO minNnz, maxNnz, numMyNnz = Teuchos::as<GO>(A->getNodeNumEntries());
MueLu_maxAll(comm, numMyNnz, maxNnz);
MueLu_minAll(comm, (numMyNnz > 0 ? numMyNnz : maxNnz), minNnz); // min nnz over all active processors
double imbalance = Teuchos::as<double>(maxNnz)/minNnz;
if (imbalance > nonzeroImbalance)
test4 = true;
msg4 = "\n nonzero imbalance = " + Teuchos::toString(imbalance) + ", max allowable = " + Teuchos::toString(nonzeroImbalance);
}
if (!test3 && !test4) {
GetOStream(Statistics0) << "Repartitioning? NO:" << msg3 + msg4 << std::endl;
Set<RCP<const Import> >(currentLevel, "Importer", Teuchos::null);
return;
}
GetOStream(Statistics0) << "Repartitioning? YES:" << msg3 + msg4 << std::endl;
GO indexBase = rowMap->getIndexBase();
Xpetra::UnderlyingLib lib = rowMap->lib();
int myRank = comm->getRank();
//.........这里部分代码省略.........
示例13: m
void RebalanceTransferFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::Build(Level& fineLevel, Level& coarseLevel) const {
FactoryMonitor m(*this, "Build", coarseLevel);
const ParameterList& pL = GetParameterList();
int implicit = !pL.get<bool>("repartition: rebalance P and R");
int writeStart = pL.get<int> ("write start");
int writeEnd = pL.get<int> ("write end");
if (writeStart == 0 && fineLevel.GetLevelID() == 0 && writeStart <= writeEnd && IsAvailable(fineLevel, "Coordinates")) {
std::string fileName = "coordinates_level_0.m";
RCP<MultiVector> fineCoords = fineLevel.Get< RCP<MultiVector> >("Coordinates");
if (fineCoords != Teuchos::null)
Utils::Write(fileName, *fineCoords);
}
RCP<const Import> importer = Get<RCP<const Import> >(coarseLevel, "Importer");
if (implicit) {
// Save the importer, we'll need it for solve
coarseLevel.Set("Importer", importer, NoFactory::get());
}
RCP<ParameterList> params = rcp(new ParameterList());;
params->set("printLoadBalancingInfo", true);
params->set("printCommInfo", true);
std::string transferType = pL.get<std::string>("type");
if (transferType == "Interpolation") {
RCP<Matrix> originalP = Get< RCP<Matrix> >(coarseLevel, "P");
{
// This line must be after the Get call
SubFactoryMonitor m1(*this, "Rebalancing prolongator", coarseLevel);
if (implicit || importer.is_null()) {
GetOStream(Runtime0) << "Using original prolongator" << std::endl;
Set(coarseLevel, "P", originalP);
} else {
// P is the transfer operator from the coarse grid to the fine grid.
// P must transfer the data from the newly reordered coarse A to the
// (unchanged) fine A. This means that the domain map (coarse) of P
// must be changed according to the new partition. The range map
// (fine) is kept unchanged.
//
// The domain map of P must match the range map of R. See also note
// below about domain/range map of R and its implications for P.
//
// To change the domain map of P, P needs to be fillCompleted again
// with the new domain map. To achieve this, P is copied into a new
// matrix that is not fill-completed. The doImport() operation is
// just used here to make a copy of P: the importer is trivial and
// there is no data movement involved. The reordering actually
// happens during the fillComplete() with domainMap == importer->getTargetMap().
RCP<Matrix> rebalancedP = originalP;
RCP<const CrsMatrixWrap> crsOp = rcp_dynamic_cast<const CrsMatrixWrap>(originalP);
TEUCHOS_TEST_FOR_EXCEPTION(crsOp == Teuchos::null, Exceptions::BadCast, "Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed");
RCP<CrsMatrix> rebalancedP2 = crsOp->getCrsMatrix();
TEUCHOS_TEST_FOR_EXCEPTION(rebalancedP2 == Teuchos::null, std::runtime_error, "Xpetra::CrsMatrixWrap doesn't have a CrsMatrix");
{
SubFactoryMonitor subM(*this, "Rebalancing prolongator -- fast map replacement", coarseLevel);
RCP<const Import> newImporter = ImportFactory::Build(importer->getTargetMap(), rebalancedP->getColMap());
rebalancedP2->replaceDomainMapAndImporter(importer->getTargetMap(), newImporter);
}
///////////////////////// EXPERIMENTAL
// TODO FIXME somehow we have to transfer the striding information of the permuted domain/range maps.
// That is probably something for an external permutation factory
// if (originalP->IsView("stridedMaps"))
// rebalancedP->CreateView("stridedMaps", originalP);
///////////////////////// EXPERIMENTAL
Set(coarseLevel, "P", rebalancedP);
if (IsPrint(Statistics1))
GetOStream(Statistics1) << PerfUtils::PrintMatrixInfo(*rebalancedP, "P (rebalanced)", params);
}
}
if (importer.is_null()) {
if (IsAvailable(coarseLevel, "Nullspace"))
Set(coarseLevel, "Nullspace", Get<RCP<MultiVector> >(coarseLevel, "Nullspace"));
if (pL.isParameter("Coordinates") && pL.get< RCP<const FactoryBase> >("Coordinates") != Teuchos::null)
if (IsAvailable(coarseLevel, "Coordinates"))
Set(coarseLevel, "Coordinates", Get< RCP<MultiVector> >(coarseLevel, "Coordinates"));
return;
}
if (pL.isParameter("Coordinates") &&
pL.get< RCP<const FactoryBase> >("Coordinates") != Teuchos::null &&
IsAvailable(coarseLevel, "Coordinates")) {
RCP<MultiVector> coords = Get<RCP<MultiVector> >(coarseLevel, "Coordinates");
// This line must be after the Get call
SubFactoryMonitor subM(*this, "Rebalancing coordinates", coarseLevel);
//.........这里部分代码省略.........
示例14: Input
void NullspacePresmoothFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::DeclareInput(Level ¤tLevel) const {
Input(currentLevel, "Nullspace");
if (currentLevel.GetLevelID() == 0)
Input(currentLevel, "A");
}
示例15: CallBuild
//!
virtual void CallBuild(Level & requestedLevel) const {
#ifdef HAVE_MUELU_DEBUG
TEUCHOS_TEST_FOR_EXCEPTION((multipleCallCheck_ == ENABLED) && (multipleCallCheckGlobal_ == ENABLED) && (lastLevel_ == &requestedLevel),
Exceptions::RuntimeError,
this->ShortClassName() << "::Build() called twice for the same level (levelID=" << requestedLevel.GetLevelID()
<< "). This is likely due to a configuration error.");
if (multipleCallCheck_ == FIRSTCALL) multipleCallCheck_ = ENABLED;
lastLevel_ = &requestedLevel;
#endif
TEUCHOS_TEST_FOR_EXCEPTION(requestedLevel.GetPreviousLevel() == Teuchos::null, Exceptions::RuntimeError, "LevelID = " << requestedLevel.GetLevelID());
Build(*requestedLevel.GetPreviousLevel(), requestedLevel);
}