Skip to content

Commit

Permalink
MueLu: CLANGgit push origin develop:csiefer-maxwell1-fix!
Browse files Browse the repository at this point in the history
  • Loading branch information
csiefer2 committed Jun 10, 2024
1 parent df3c21d commit ecb347d
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 58 deletions.
13 changes: 6 additions & 7 deletions packages/muelu/src/Interface/MueLu_HierarchyManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ class HierarchyManager : public HierarchyFactory<Scalar, LocalOrdinal, GlobalOrd
H.SetFuseProlongationAndUpdate(fuseProlongationAndUpdate_);

H.Clear();


// There are few issues with using Keep in the interpreter:
// 1. Hierarchy::Keep interface takes a name and a factory. If
Expand Down Expand Up @@ -246,7 +245,7 @@ class HierarchyManager : public HierarchyFactory<Scalar, LocalOrdinal, GlobalOrd
H.AddLevel(newLevel);
}
}

// Matrices to print
for (auto iter = matricesToPrint_.begin(); iter != matricesToPrint_.end(); iter++)
ExportDataSetKeepFlags(H, iter->second, iter->first);
Expand All @@ -262,8 +261,8 @@ class HierarchyManager : public HierarchyFactory<Scalar, LocalOrdinal, GlobalOrd

// Data to keep only (these do not have a level, so we do all levels)
for (int i = 0; i < dataToKeep_.size(); i++)
ExportDataSetKeepFlagsAll(H, dataToKeep_[i]);
ExportDataSetKeepFlagsAll(H, dataToKeep_[i]);

int levelID = 0;
int lastLevelID = numDesiredLevel_ - 1;
bool isLastLevel = false;
Expand All @@ -279,7 +278,7 @@ class HierarchyManager : public HierarchyFactory<Scalar, LocalOrdinal, GlobalOrd
isLastLevel = r || (levelID == lastLevelID);
levelID++;
}

if (!matvecParams_.is_null())
H.SetMatvecParams(matvecParams_);
H.AllocateLevelMultiVectors(sizeOfMultiVectors_);
Expand Down Expand Up @@ -318,10 +317,10 @@ class HierarchyManager : public HierarchyFactory<Scalar, LocalOrdinal, GlobalOrd
} // SetupHierarchy

//! Set the number of desired levels.
void SetNumDesiredLevel(int numDesiredLevel){numDesiredLevel_ = numDesiredLevel;}
void SetNumDesiredLevel(int numDesiredLevel) { numDesiredLevel_ = numDesiredLevel; }

//! Get the number of desired levels.
int GetNumDesiredLevel(){return numDesiredLevel_;}
int GetNumDesiredLevel() { return numDesiredLevel_; }

//@}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ void ParameterListInterpreter<Scalar, LocalOrdinal, GlobalOrdinal, Node>::

// Generic data keeping (this keeps the data on all levels)
if (paramList.isParameter("keep data"))
this->dataToKeep_ = Teuchos::getArrayFromStringParameter<std::string>(paramList, "keep data");
this->dataToKeep_ = Teuchos::getArrayFromStringParameter<std::string>(paramList, "keep data");

// Export level data
if (paramList.isSublist("export data")) {
Expand Down
2 changes: 1 addition & 1 deletion packages/muelu/src/MueCentral/MueLu_Hierarchy_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ class Hierarchy : public BaseClass {
template <class S2, class LO2, class GO2, class N2>
friend class Hierarchy;


int LastLevelID() const { return Levels_.size() - 1; }

private:
void DumpCurrentGraph(int level) const;

Expand Down
37 changes: 13 additions & 24 deletions packages/muelu/src/Operators/MueLu_Maxwell1_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@
#include <MueLu_ML2MueLuParameterTranslator.hpp>
#include <MueLu_RefMaxwellSmoother.hpp>



#ifdef HAVE_MUELU_CUDA
#include "cuda_profiler_api.h"
#endif
Expand Down Expand Up @@ -146,14 +144,10 @@ void Maxwell1<Scalar, LocalOrdinal, GlobalOrdinal, Node>::setParameters(Teuchos:
newList.set("maxwell1: nodal smoother fix zero diagonal threshold", 1e-10);
newList.sublist("maxwell1: 22list").set("rap: fix zero diagonals", true);
newList.sublist("maxwell1: 22list").set("rap: fix zero diagonals threshold", 1e-10);

list = newList;
}





std::string mode_string = list.get("maxwell1: mode", MasterList::getDefault<std::string>("maxwell1: mode"));
applyBCsTo22_ = list.get("maxwell1: apply BCs to 22", false);
dump_matrices_ = list.get("maxwell1: dump matrices", MasterList::getDefault<bool>("maxwell1: dump matrices"));
Expand Down Expand Up @@ -276,7 +270,6 @@ void Maxwell1<Scalar, LocalOrdinal, GlobalOrdinal, Node>::compute(bool reuse) {
ReitzingerPFactory to generate the edge P and A matrices.
*/


#ifdef HAVE_MUELU_CUDA
if (parameterList_.get<bool>("maxwell1: cuda profile setup", false)) cudaProfilerStart();
#endif
Expand Down Expand Up @@ -321,14 +314,14 @@ void Maxwell1<Scalar, LocalOrdinal, GlobalOrdinal, Node>::compute(bool reuse) {
that we need to keep the importers in sync too */
if (precList22_.isParameter("repartition: enable")) {
bool repartition = precList22_.get<bool>("repartition: enable");
precList11_.set("repartition: enable", repartition);
precList11_.set("repartition: enable", repartition);

// If we're repartitioning (2,2), we need to rebalance for (1,1) to do the right thing,
// as well as keep the importers
if (repartition) {
// FIXME: We should probably update rather than clobber
precList22_.set("repartition: save importer",true);
//precList22_.set("repartition: rebalance P and R", false);
precList22_.set("repartition: save importer", true);
// precList22_.set("repartition: rebalance P and R", false);
precList22_.set("repartition: rebalance P and R", true);
}

Expand Down Expand Up @@ -400,7 +393,7 @@ void Maxwell1<Scalar, LocalOrdinal, GlobalOrdinal, Node>::compute(bool reuse) {
}

////////////////////////////////////////////////////////////////////////////////
// Build (2,2) hierarchy
// Build (2,2) hierarchy
Hierarchy22_ = MueLu::CreateXpetraPreconditioner(Kn_Matrix_, precList22_);

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -483,7 +476,7 @@ void Maxwell1<Scalar, LocalOrdinal, GlobalOrdinal, Node>::compute(bool reuse) {
importer = NodeL->Get<RCP<const Import> >("Importer");
EdgeL->Set("NodeImporter", importer);
}

// If we repartition a processor away, a RCP<Operator> is stuck
// on the level instead of an RCP<Matrix>
if (!OldSmootherMatrix.is_null() && !NodalP_ones.is_null()) {
Expand All @@ -502,7 +495,6 @@ void Maxwell1<Scalar, LocalOrdinal, GlobalOrdinal, Node>::compute(bool reuse) {
RAPlist.set("rap: fix zero diagonals", false);
RCP<Matrix> NewKn = Maxwell_Utils<SC, LO, GO, NO>::PtAPWrapper(OldSmootherMatrix, NodalP_ones, RAPlist, labelstr);


// If there's an importer, we need to Rebalance the NewKn
if (!importer.is_null()) {
ParameterList rebAcParams;
Expand All @@ -514,15 +506,14 @@ void Maxwell1<Scalar, LocalOrdinal, GlobalOrdinal, Node>::compute(bool reuse) {

Level fLevel, cLevel;
cLevel.SetPreviousLevel(Teuchos::rcpFromRef(fLevel));
cLevel.Set("InPlaceMap",InPlaceMap);
cLevel.Set("A",NewKn);
cLevel.Set("InPlaceMap", InPlaceMap);
cLevel.Set("A", NewKn);
cLevel.Request("A", newAfact.get());
newAfact->Build(fLevel,cLevel);
newAfact->Build(fLevel, cLevel);

NewKn = cLevel.Get<RCP<Matrix> >("A", newAfact.get());
EdgeL->Set("NodeMatrix", NewKn);
}
else {
} else {
EdgeL->Set("NodeMatrix", NewKn);
}

Expand Down Expand Up @@ -551,7 +542,6 @@ void Maxwell1<Scalar, LocalOrdinal, GlobalOrdinal, Node>::compute(bool reuse) {

} // end Hierarchy22 loop


////////////////////////////////////////////////////////////////////////////////
// Generating the (1,1) Hierarchy
std::string fine_smoother = precList11_.get<std::string>("smoother: type");
Expand All @@ -575,12 +565,11 @@ void Maxwell1<Scalar, LocalOrdinal, GlobalOrdinal, Node>::compute(bool reuse) {
Hierarchy11_->SetProcRankVerbose(SM_Matrix_->getDomainMap()->getComm()->getRank());

// Stick the non-serializible data on the hierarchy and do setup
if(nonSerialList11.numParams() > 0) {
if (nonSerialList11.numParams() > 0) {
HierarchyUtils<SC, LO, GO, NO>::AddNonSerializableDataToHierarchy(*mueLuFactory, *Hierarchy11_, nonSerialList11);
}
}
mueLuFactory->SetupHierarchy(*Hierarchy11_);


if (refmaxwellCoarseSolve) {
GetOStream(Runtime0) << "Maxwell1::compute(): Setting up RefMaxwell coarse solver" << std::endl;
auto coarseLvl = Hierarchy11_->GetLevel(Hierarchy11_->GetNumLevels() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
void RepartitionFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::DeclareInput(Level& currentLevel) const {
Input(currentLevel, "A");
Input(currentLevel, "number of partitions");
Input(currentLevel, "Partition");
Input(currentLevel, "Partition");
}

template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
Expand Down Expand Up @@ -405,10 +405,10 @@ void RepartitionFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(Level&

// Importer saving
bool save_importer = pL.get<bool>("repartition: save importer");
if(save_importer) {
currentLevel.Set("Importer",rowMapImporter,NoFactory::get());
if (save_importer) {
currentLevel.Set("Importer", rowMapImporter, NoFactory::get());
currentLevel.AddKeepFlag("Importer", NoFactory::get(), MueLu::Final);
currentLevel.RemoveKeepFlag("Importer", NoFactory::get(), MueLu::UserData);//FIXME: This is a hack
currentLevel.RemoveKeepFlag("Importer", NoFactory::get(), MueLu::UserData); // FIXME: This is a hack
}
// ======================================================================================================
// Print some data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,16 @@ void ReitzingerPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::BuildP(Level
}

// Exponential memory reallocation, if needed
if(current + 1 >= max_edges) {
max_edges*=2;
if (current + 1 >= max_edges) {
max_edges *= 2;
D0_colind.resize(max_edges);
D0_values.resize(max_edges);
D0_values.resize(max_edges);
}
if(current / 2 + 1 >= D0_rowptr.size()) {
D0_rowptr.resize(2*D0_rowptr.size()+1);
if (current / 2 + 1 >= D0_rowptr.size()) {
D0_rowptr.resize(2 * D0_rowptr.size() + 1);
}

// NOTE: "i" here might not be a valid local column id, so we read it from the map
// NOTE: "i" here might not be a valid local column id, so we read it from the map
D0_colind[current] = local_column_i;
D0_values[current] = -1;
current++;
Expand All @@ -325,7 +325,7 @@ void ReitzingerPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::BuildP(Level
D0_values.resize(current);

// Handle empty ranks gracefully
if(num_coarse_edges == 0) {
if (num_coarse_edges == 0) {
D0_rowptr[0] = 0;
D0_rowptr[1] = 0;
}
Expand Down Expand Up @@ -430,7 +430,7 @@ void ReitzingerPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::BuildP(Level
// TODO: Something like this *might* work. But this specifically, doesn't
// Pe = XMM::Multiply(*D0_Pn_nonghosted,false,*D0_coarse_m,true,dummy,out0,true,true,"(D0*Pn)*D0c'",mm_params);
}

/* Weed out the +/- entries, shrinking the matrix as we go */
{
SubFactoryMonitor m2(*this, "Generate Pe (post-fix)", coarseLevel);
Expand Down
20 changes: 7 additions & 13 deletions packages/muelu/test/maxwell/Maxwell3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,6 @@ int main_(Teuchos::CommandLineProcessor& clp, Xpetra::UnderlyingLib lib, int arg
clp.setOption("ensure-kn",
"no-ensure-kn", &ensure_kn, "generate a kn matrix if the user doesn't provide one");



std::string S_file, D0_file, M1_file, M0_file;
if (!Teuchos::ScalarTraits<Scalar>::isComplex) {
S_file = "S.mat";
Expand Down Expand Up @@ -593,8 +591,7 @@ int main_(Teuchos::CommandLineProcessor& clp, Xpetra::UnderlyingLib lib, int arg
clp.setOption("x0", &x0_file);
std::string GmhdA_file = "";
clp.setOption("GmhdA", &GmhdA_file);



clp.recogniseAllOptions(true);
switch (clp.parse(argc, argv)) {
case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS;
Expand Down Expand Up @@ -689,20 +686,17 @@ int main_(Teuchos::CommandLineProcessor& clp, Xpetra::UnderlyingLib lib, int arg
else
Ms_Matrix = M1_Matrix;
if (Kn_file != "") {
*out<<"User provided Kn matrix"<<std::endl;
*out << "User provided Kn matrix" << std::endl;
Kn_Matrix = Xpetra::IO<SC, LO, GO, NO>::Read(Kn_file, node_map);
}
else if(ensure_kn) {
} else if (ensure_kn) {
// The user requested we generate Kn_Matrix with an SpGEMM
Teuchos::ParameterList params;
*out<<"Making Kn Matrix as requested by yser"<<std::endl;
Kn_Matrix = MueLu::Maxwell_Utils<SC,LO,GO,NO>::PtAPWrapper(SM_Matrix,D0_Matrix,params,"User Kn");
}
else {
*out<<"NOT using a Kn matrix"<<std::endl;
*out << "Making Kn Matrix as requested by yser" << std::endl;
Kn_Matrix = MueLu::Maxwell_Utils<SC, LO, GO, NO>::PtAPWrapper(SM_Matrix, D0_Matrix, params, "User Kn");
} else {
*out << "NOT using a Kn matrix" << std::endl;
}


if ((M0inv_file == "") && (M0_file != "")) {
// nodal mass matrix
RCP<Matrix> M0_Matrix = Xpetra::IO<SC, LO, GO, NO>::Read(M0_file, node_map);
Expand Down

0 comments on commit ecb347d

Please sign in to comment.