Skip to content

Commit

Permalink
Merge pull request #188 from labmec/metis-reorder
Browse files Browse the repository at this point in the history
feat: working metis reorder
  • Loading branch information
giavancini authored Jun 23, 2023
2 parents 441e208 + 04cddc6 commit c0b4375
Show file tree
Hide file tree
Showing 27 changed files with 134 additions and 91 deletions.
57 changes: 41 additions & 16 deletions Analysis/TPZAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "TPZLagrangeMultiplier.h" // for TPZLagrangeMultiplier
#include "TPZSloanRenumbering.h" // for TPZSloanRenumbering
#include "TPZCutHillMcKee.h"
#ifdef USING_METIS
#ifdef PZ_USING_METIS
#include "pzmetis.h"
#endif
#include "pzadmchunk.h" // for TPZAdmChunkVector
Expand Down Expand Up @@ -67,6 +67,7 @@ static TPZLogger loggerPrecond("pz.analysis.precondgraph");
#endif

//@orlandini: does anyone know if boost renumbering still works?
//@shauer: I don't think so. This #define structure is also now deprecated. I vote for deleting
#undef USE_BOOST_RENUMBERING
#if defined(USING_BOOST) && defined(USE_BOOST_RENUMBERING)
#include "TPZBoostGraph.h"
Expand All @@ -81,14 +82,13 @@ static TPZLogger loggerPrecond("pz.analysis.precondgraph");
* @ingroup analysis
*/

#ifdef USING_METIS
#define RENUMBER TPZMetis()
#else
#define RENUMBER TPZSloanRenumbering()
#endif
//#ifdef PZ_USING_METIS
//#define RENUMBER TPZMetis()
//#else
//#define RENUMBER TPZSloanRenumbering()
//#endif
//#define RENUMBER TPZCutHillMcKee() //TPZCutHillMcKee usually performs worse than metis and sloan. Use carefully


#endif

using namespace std;
Expand Down Expand Up @@ -133,33 +133,58 @@ void TPZAnalysis::SetStructuralMatrix(TPZAutoPointer<TPZStructMatrix> strmatrix)
// #endif
}
TPZAnalysis::TPZAnalysis() :
TPZRegisterClassId(&TPZAnalysis::ClassId),
fRenumber(new RENUMBER){
TPZRegisterClassId(&TPZAnalysis::ClassId){
}


TPZAnalysis::TPZAnalysis(TPZCompMesh *mesh, bool mustOptimizeBandwidth, std::ostream &out) :
TPZAnalysis::TPZAnalysis(TPZCompMesh *mesh, const RenumType& renumtype, std::ostream &out) :
TPZRegisterClassId(&TPZAnalysis::ClassId),
fSolType(mesh->GetSolType()),
// fRhs(fSolType == EComplex ? true : false),
fSolution(fSolType == EComplex ? true : false),
fRenumber(new RENUMBER)
fSolution(fSolType == EComplex ? true : false)
{
//we must not call virtual methods in constructor
bool mustOptimizeBandwidth = false;
if (renumtype != RenumType::ENone){
CreateRenumberObject(renumtype);
mustOptimizeBandwidth = true;
}
this->SetCompMeshInit(mesh, mustOptimizeBandwidth);
}

TPZAnalysis::TPZAnalysis(TPZAutoPointer<TPZCompMesh> mesh, bool mustOptimizeBandwidth, std::ostream &out) :
TPZAnalysis::TPZAnalysis(TPZAutoPointer<TPZCompMesh> mesh, const RenumType& renumtype, std::ostream &out) :
TPZRegisterClassId(&TPZAnalysis::ClassId),
fSolType(mesh->GetSolType()),
// fRhs(fSolType == EComplex ? true : false),
fSolution(fSolType == EComplex ? true : false),
fRenumber(new RENUMBER)
fSolution(fSolType == EComplex ? true : false)
{
//we must not call virtual methods in constructor
bool mustOptimizeBandwidth = false;
if (renumtype != RenumType::ENone){
CreateRenumberObject(renumtype);
mustOptimizeBandwidth = true;
}
this->SetCompMeshInit(mesh.operator ->(), mustOptimizeBandwidth);
}

void TPZAnalysis::CreateRenumberObject(const RenumType& renumtype) {
switch (renumtype) {
case RenumType::ESloan:
fRenumber = new TPZSloanRenumbering;
break;
case RenumType::ECutHillMcKee:
fRenumber = new TPZCutHillMcKee;
break;
#ifdef PZ_USING_METIS
case RenumType::EMetis:
fRenumber = new TPZMetis;
break;
#endif
default:
DebugStop(); // Should not arrive here
break;
}
}

void TPZAnalysis::SetCompMeshInit(TPZCompMesh *mesh, bool mustOptimizeBandwidth)
{
if(mesh)
Expand Down
21 changes: 16 additions & 5 deletions Analysis/TPZAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ namespace Precond{
}
}

enum class RenumType {ENone, ESloan, ECutHillMcKee, EMetis};

/**
* @ingroup analysis
* @brief Abstract class defining the interface for performing a Finite Element Analysis.*/
Expand Down Expand Up @@ -104,12 +106,21 @@ class TPZAnalysis : public TPZSavable {
/** @brief Create an empty TPZAnalysis object */
TPZAnalysis();

/** @brief Create an TPZAnalysis object from one mesh pointer */
TPZAnalysis(TPZCompMesh *mesh, bool mustOptimizeBandwidth = true, std::ostream &out = std::cout);

#ifdef PZ_USING_METIS
/** @brief Create an TPZAnalysis object from one mesh pointer */
TPZAnalysis(TPZCompMesh *mesh, const RenumType& renumtype = RenumType::EMetis, std::ostream &out = std::cout);
/** @brief Create an TPZAnalysis object from one mesh auto pointer object */
TPZAnalysis(TPZAutoPointer<TPZCompMesh> mesh, const RenumType& renumtype = RenumType::EMetis, std::ostream &out = std::cout);
#else
/** @brief Create an TPZAnalysis object from one mesh pointer */
TPZAnalysis(TPZCompMesh *mesh, const RenumType& renumtype = RenumType::ESloan, std::ostream &out = std::cout);
/** @brief Create an TPZAnalysis object from one mesh auto pointer object */
TPZAnalysis(TPZAutoPointer<TPZCompMesh> mesh, const RenumType& renumtype = RenumType::ESloan, std::ostream &out = std::cout);
#endif

/** @brief Create an TPZAnalysis object from one mesh auto pointer object */
TPZAnalysis(TPZAutoPointer<TPZCompMesh> mesh, bool mustOptimizeBandwidth = true, std::ostream &out = std::cout);

void CreateRenumberObject(const RenumType& renumtype);

/** @} */
/** @brief Destructor: deletes all protected dynamic allocated objects */
virtual ~TPZAnalysis(void);
Expand Down
8 changes: 4 additions & 4 deletions Analysis/TPZEigenAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ TPZEigenAnalysis::TPZEigenAnalysis()
}

TPZEigenAnalysis::TPZEigenAnalysis(TPZCompMesh *mesh,
bool mustOptimizeBandwidth, std::ostream &out)
: TPZAnalysis(mesh, mustOptimizeBandwidth,out)
const RenumType& renumtype, std::ostream &out)
: TPZAnalysis(mesh, renumtype,out)
{

}

TPZEigenAnalysis::TPZEigenAnalysis(TPZAutoPointer<TPZCompMesh> mesh,
bool mustOptimizeBandwidth,
const RenumType& renumtype,
std::ostream &out)
: TPZAnalysis(mesh, mustOptimizeBandwidth, out)
: TPZAnalysis(mesh, renumtype, out)
{

}
Expand Down
13 changes: 11 additions & 2 deletions Analysis/TPZEigenAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ class TPZEigenAnalysis : public TPZAnalysis{
/** @{ */
/** @brief Create an empty TPZEigenAnalysis object*/
TPZEigenAnalysis();

#ifdef PZ_USING_METIS
/** @brief Create an TPZEigenAnalysis object from one mesh pointer */
TPZEigenAnalysis(TPZCompMesh *mesh, bool mustOptimizeBandwidth = true, std::ostream &out = std::cout);
TPZEigenAnalysis(TPZCompMesh *mesh, const RenumType& renumtype = RenumType::EMetis, std::ostream &out = std::cout);
/** @brief Create an TPZEigenAnalysis object from one mesh auto pointer object */
TPZEigenAnalysis(TPZAutoPointer<TPZCompMesh> mesh, bool mustOptimizeBandwidth = true, std::ostream &out = std::cout);
TPZEigenAnalysis(TPZAutoPointer<TPZCompMesh> mesh, const RenumType& renumtype = RenumType::EMetis, std::ostream &out = std::cout);
#else
/** @brief Create an TPZEigenAnalysis object from one mesh pointer */
TPZEigenAnalysis(TPZCompMesh *mesh, const RenumType& renumtype = RenumType::ESloan, std::ostream &out = std::cout);
/** @brief Create an TPZEigenAnalysis object from one mesh auto pointer object */
TPZEigenAnalysis(TPZAutoPointer<TPZCompMesh> mesh, const RenumType& renumtype = RenumType::ESloan, std::ostream &out = std::cout);

#endif

/** @} */
/** @name FEM*/
Expand Down
10 changes: 5 additions & 5 deletions Analysis/TPZLinearAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ TPZLinearAnalysis::TPZLinearAnalysis() : TPZAnalysis()
}

TPZLinearAnalysis::TPZLinearAnalysis(TPZCompMesh *mesh,
bool mustOptimizeBandwidth,
const RenumType& renumtype,
std::ostream &out) :
TPZAnalysis(mesh,mustOptimizeBandwidth,out),
TPZAnalysis(mesh,renumtype,out),
fRhs(fSolType == EComplex ? true : false)
{
}

TPZLinearAnalysis::TPZLinearAnalysis(TPZAutoPointer<TPZCompMesh> mesh,
bool mustOptimizeBandwidth,
const RenumType& renumtype,
std::ostream &out) :
TPZAnalysis(mesh,mustOptimizeBandwidth,out),
TPZAnalysis(mesh,renumtype,out),
fRhs(fSolType == EComplex ? true : false)
{
}
Expand Down Expand Up @@ -350,4 +350,4 @@ INSTANTIATE_TEMPLATES(CSTATE)

#undef INSTANTIATE_TEMPLATES

template class TPZRestoreClass<TPZLinearAnalysis>;
template class TPZRestoreClass<TPZLinearAnalysis>;
14 changes: 10 additions & 4 deletions Analysis/TPZLinearAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ class TPZLinearAnalysis : public TPZAnalysis{
/** @brief Create an empty TPZLinearAnalysis object */
TPZLinearAnalysis();

#ifdef PZ_USING_METIS
/** @brief Create an TPZLinearAnalysis object from one mesh pointer */
TPZLinearAnalysis(TPZCompMesh *mesh, bool mustOptimizeBandwidth = true, std::ostream &out = std::cout);

TPZLinearAnalysis(TPZCompMesh *mesh, const RenumType& renumtype = RenumType::EMetis, std::ostream &out = std::cout);
/** @brief Create an TPZLinearAnalysis object from one mesh auto pointer object */
TPZLinearAnalysis(TPZAutoPointer<TPZCompMesh> mesh, bool mustOptimizeBandwidth = true, std::ostream &out = std::cout);
TPZLinearAnalysis(TPZAutoPointer<TPZCompMesh> mesh, const RenumType& renumtype = RenumType::EMetis, std::ostream &out = std::cout);
#else
/** @brief Create an TPZLinearAnalysis object from one mesh pointer */
TPZLinearAnalysis(TPZCompMesh *mesh, const RenumType& renumtype = RenumType::ESloan, std::ostream &out = std::cout);
/** @brief Create an TPZLinearAnalysis object from one mesh auto pointer object */
TPZLinearAnalysis(TPZAutoPointer<TPZCompMesh> mesh, const RenumType& renumtype = RenumType::ESloan, std::ostream &out = std::cout);
#endif
/** @} */

/** @name FEM */
Expand Down Expand Up @@ -108,4 +114,4 @@ INSTANTIATE_TEMPLATES(STATE)
INSTANTIATE_TEMPLATES(CSTATE)
#undef INSTANTIATE_TEMPLATES

#endif
#endif
2 changes: 1 addition & 1 deletion Analysis/pzeuleranalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fEvolCFL(0), fpBlockDiag(NULL),fHasFrontalPreconditioner(0)
}

TPZEulerAnalysis::TPZEulerAnalysis(TPZFlowCompMesh *mesh, std::ostream &out):
TPZLinearAnalysis(mesh, true, out), fFlowCompMesh(mesh),
TPZLinearAnalysis(mesh, RenumType::ESloan, out), fFlowCompMesh(mesh),
fRhsLast(),
fNewtonEps(1e-9), fNewtonMaxIter(10),
fTimeIntEps(1e-8), fTimeIntMaxIter(100),
Expand Down
2 changes: 1 addition & 1 deletion Analysis/pznonlinanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TPZNonLinearAnalysis::TPZNonLinearAnalysis() : TPZLinearAnalysis() {
fSolution.Zero();
}

TPZNonLinearAnalysis::TPZNonLinearAnalysis(TPZCompMesh *mesh,std::ostream &out) : TPZLinearAnalysis(mesh,true,out) {
TPZNonLinearAnalysis::TPZNonLinearAnalysis(TPZCompMesh *mesh,std::ostream &out) : TPZLinearAnalysis(mesh,RenumType::ESloan,out) {
if(Mesh()) Mesh()->Solution().Zero();
fSolution.Zero();
}
Expand Down
2 changes: 1 addition & 1 deletion Analysis/pzsmanal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using namespace std;
// Construction/Destruction

TPZSubMeshAnalysis::TPZSubMeshAnalysis(TPZSubCompMesh *mesh) : TPZRegisterClassId(&TPZSubMeshAnalysis::ClassId),
TPZLinearAnalysis(mesh,true), fReducableStiff(0){
TPZLinearAnalysis(mesh), fReducableStiff(0){
fMesh = mesh;
if (fMesh)
{
Expand Down
10 changes: 5 additions & 5 deletions External/pzmetis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "pzmetis.h"

#ifdef USING_METIS
#ifdef PZ_USING_METIS
#include <math.h>
extern "C" {
#include "metis.h"
Expand All @@ -23,10 +23,10 @@ using namespace std;

TPZMetis::TPZMetis() : TPZRenumbering()
{
#ifndef USING_METIS
#ifndef PZ_USING_METIS
PZError<<"TPZMetis depends on the Metis library\n";
PZError<<"Please reconfigure NeoPZ library using:\n";
PZError<<"USING_METIS=ON"<<std::endl;
PZError<<"PZ_USING_METIS=ON"<<std::endl;
DebugStop();
#endif
}
Expand Down Expand Up @@ -123,7 +123,7 @@ void TPZMetis::Resequence(TPZVec<int64_t> &perm, TPZVec<int64_t> &inverseperm) {
perm[nod] = inverseperm[nod] = nod;
}

#ifdef USING_METIS
#ifdef PZ_USING_METIS
TPZVec<idx_t> nodegraphInt(0),nodegraphindexInt(0);
idx_t NNodes = (idx_t) fNNodes;
int64_t n, sz = nodegraph.NElements();
Expand Down Expand Up @@ -186,7 +186,7 @@ void TPZMetis::Subdivide(int nParts, TPZVec < int > & Domains)
}
#endif

#ifdef USING_METIS
#ifdef PZ_USING_METIS
TPZManVector<int> AdjacencyInt,AdjacencyIndexInt;
int64_t n, nVertices = AdjacencyIndex.NElements();
AdjacencyIndexInt.Resize(nVertices,0);
Expand Down
2 changes: 1 addition & 1 deletion External/pzmetis.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file
* @brief Contains TPZMetis class which implements the renumbering for elements of a mesh to minimize the band using Metis library. It depends on NeoPZ being configured with USING_METIS=ON
* @brief Contains TPZMetis class which implements the renumbering for elements of a mesh to minimize the band using Metis library. It depends on NeoPZ being configured with PZ_USING_METIS=ON
*/

#ifndef TPZMETIS_H
Expand Down
6 changes: 3 additions & 3 deletions Solvers/TPZPardisoSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ void TPZPardisoSolver<TVar>::Decompose(TPZMatrix<TVar> *mat)
(the first step or last step with a failure)
in a sequence of solutions needed for identical sparsity patterns.
*/
//fParam[4] No user fill-in reducing permutation
//fParam[4] No user fill-in reducing permutation. 0 uses pardiso reordering, 1 uses ours, 2 uses pardiso and returns perm
if constexpr (!is_complex<TVar>::value){
fParam[3] = fSymmetry == SymProp::NonSym ? 10*6+1 : 10*6+2;
if(fProperty == MProperty::EIndefinite) fParam[4] =1;
if(fProperty == MProperty::EIndefinite) fParam[4] = 1; // 0 uses pardiso reordering, 1 uses ours
}else{
fParam[3] = 0;
fParam[4] = 0;
fParam[4] = 0; // 0 uses pardiso reordering, 1 uses ours
}
//fParam[9] Perturb the pivot elements with 1E-fParam[9]
fParam[9] = 13;
Expand Down
10 changes: 5 additions & 5 deletions SubStruct/pzdohrstructmatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ static void DecomposeInternal(TPZAutoPointer<TPZDohrSubstructCondense<TVar> > su
#define NOMETIS \
PZError<<"TPZDohrStructMatrix requires Metis library\n";\
PZError<<"Please reconfigure NeoPZ library with:\n";\
PZError<<"USING_METIS=ON"<<std::endl;\
PZError<<"PZ_USING_METIS=ON"<<std::endl;\
DebugStop();
template<class TVar, class TPar>
TPZDohrStructMatrix<TVar,TPar>::TPZDohrStructMatrix() :
TPZStructMatrixT<TVar>(), fDohrAssembly(0), fDohrPrecond(0), fAccessElement()
{
#ifndef USING_METIS
#ifndef PZ_USING_METIS
NOMETIS
#endif
}
Expand All @@ -98,7 +98,7 @@ template<class TVar, class TPar>
TPZStructMatrixT<TVar>(cmesh), fDohrAssembly(0),
fDohrPrecond(0), fAccessElement()
{
#ifndef USING_METIS
#ifndef PZ_USING_METIS
NOMETIS
#endif
}
Expand All @@ -107,7 +107,7 @@ template<class TVar, class TPar>
TPZDohrStructMatrix<TVar,TPar>::TPZDohrStructMatrix(const TPZDohrStructMatrix &copy) :
TPZStructMatrixT<TVar>(copy), fDohrAssembly(copy.fDohrAssembly), fDohrPrecond(copy.fDohrPrecond), fAccessElement()
{
#ifndef USING_METIS
#ifndef PZ_USING_METIS
NOMETIS
#endif
}
Expand All @@ -122,7 +122,7 @@ template<class TVar, class TPar>
template<class TVar, class TPar>
TPZMatrix<TVar> * TPZDohrStructMatrix<TVar,TPar>::Create()
{
#ifndef USING_METIS
#ifndef PZ_USING_METIS
NOMETIS
#endif
TPZSimpleTimer timeforcopute; // init of timer for compute
Expand Down
Loading

0 comments on commit c0b4375

Please sign in to comment.