43 #include "Ifpack_ConfigDefs.h"
44 #include "Ifpack_Reordering.h"
45 #include "Ifpack_METISReordering.h"
46 #include "Ifpack_Graph.h"
47 #include "Ifpack_Graph_Epetra_CrsGraph.h"
48 #include "Ifpack_Graph_Epetra_RowMatrix.h"
49 #include "Epetra_Comm.h"
50 #include "Epetra_MultiVector.h"
51 #include "Epetra_CrsGraph.h"
52 #include "Epetra_Map.h"
53 #include "Teuchos_ParameterList.hpp"
56 #ifdef HAVE_IFPACK_METIS
58 void METIS_NodeND(
int *n, idxtype *xadj, idxtype *adjncy,
59 int *numflag,
int *options,
int *perm,
int *iperm);
65 UseSymmetricGraph_(false),
82 Reorder_.resize(NumMyRows_);
83 InvReorder_.resize(NumMyRows_);
87 Teuchos::RefCountPtr<Epetra_CrsGraph> SymGraph;
88 Teuchos::RefCountPtr<Epetra_Map> SymMap;
89 Teuchos::RefCountPtr<Ifpack_Graph_Epetra_CrsGraph> SymIFPACKGraph;
90 Teuchos::RefCountPtr<Ifpack_Graph> IFPACKGraph = Teuchos::rcp( (
Ifpack_Graph*)&Graph,
false );
95 Indices.resize(Length);
101 #ifdef HAVE_IFPACK_METIS
105 if (UseSymmetricGraph_) {
111 SymMap = Teuchos::rcp(
new Epetra_Map(NumMyRows_,0,Graph.
Comm()) );
112 SymGraph = Teuchos::rcp(
new Epetra_CrsGraph(Copy,*SymMap,0) );
114 for (
int i = 0; i < NumMyRows_ ; ++i) {
118 IFPACK_CHK_ERR(ierr);
120 for (
int j = 0 ; j < NumIndices ; ++j) {
124 SymGraph->InsertGlobalIndices(i,1,&jj);
125 SymGraph->InsertGlobalIndices(jj,1,&i);
129 IFPACK_CHK_ERR(SymGraph->OptimizeStorage());
130 IFPACK_CHK_ERR(SymGraph->FillComplete());
132 IFPACKGraph = SymIFPACKGraph;
136 vector<idxtype> xadj;
137 xadj.resize(NumMyRows_ + 1);
139 vector<idxtype> adjncy;
146 for (
int i = 0; i < NumMyRows_ ; ++i) {
148 xadj[count2+1] = xadj[count2];
150 ierr = IFPACKGraph->ExtractMyRowCopy(i, Length, NumIndices, &Indices[0]);
151 IFPACK_CHK_ERR(ierr);
153 for (
int j = 0 ; j < NumIndices ; ++j) {
156 adjncy[count++] = jj;
163 #ifdef HAVE_IFPACK_METIS
170 METIS_NodeND(&NumMyRows_, &xadj[0], &adjncy[0],
171 &numflag, &options[0],
172 &InvReorder_[0], &Reorder_[0]);
174 cerr <<
"Please configure with --enable-ifpack-metis" << endl;
175 cerr <<
"to use METIS Reordering." << endl;
187 IFPACK_CHK_ERR(
Compute(Graph));
198 if ((i < 0) || (i >= NumMyRows_))
211 if ((i < 0) || (i >= NumMyRows_))
215 return(InvReorder_[i]);
219 Epetra_MultiVector& X)
const
221 int NumVectors = X.NumVectors();
223 for (
int j = 0 ; j < NumVectors ; ++j) {
224 for (
int i = 0 ; i < NumMyRows_ ; ++i) {
225 int np = Reorder_[i];
226 X[j][np] = Xorig[j][i];
235 Epetra_MultiVector& X)
const
237 int NumVectors = X.NumVectors();
239 for (
int j = 0 ; j < NumVectors ; ++j) {
240 for (
int i = 0 ; i < NumMyRows_ ; ++i) {
241 int np = Reorder_[i];
242 X[j][i] = Xorig[j][np];
252 os <<
"*** Ifpack_METISReordering" << endl << endl;
254 os <<
"*** Reordering not yet computed." << endl;
256 os <<
"*** Number of local rows = " << NumMyRows_ << endl;
257 os <<
"Local Row\tReorder[i]\tInvReorder[i]" << endl;
258 for (
int i = 0 ; i < NumMyRows_ ; ++i) {
259 os <<
'\t' << i <<
"\t\t" << Reorder_[i] <<
"\t\t" << InvReorder_[i] << endl;
virtual int ExtractMyRowCopy(int MyRow, int LenOfIndices, int &NumIndices, int *Indices) const =0
Extracts a copy of input local row.
virtual int NumMyRows() const =0
Returns the number of local rows.
virtual int Pinv(const Epetra_MultiVector &Xorig, Epetra_MultiVector &X) const
Applies inverse reordering to multivector Xorig, whose local length equals the number of local rows...
virtual bool IsComputed() const
Returns true is the reordering object has been successfully initialized, false otherwise.
Ifpack_METISReordering()
Constructor.
virtual int NumMyNonzeros() const =0
Returns the number of local nonzero entries.
virtual int Reorder(const int i) const
Returns the reordered index of row i.
Ifpack_Graph_Epetra_CrsGraph: a class to define Ifpack_Graph as a light-weight conversion of Epetra_C...
virtual const Epetra_Comm & Comm() const =0
Returns the communicator object of the graph.
virtual int InvReorder(const int i) const
Returns the inverse reordered index of row i.
Ifpack_Graph_Epetra_RowMatrix: a class to define Ifpack_Graph as a light-weight conversion of Epetra_...
virtual int Compute(const Ifpack_Graph &Graph)
Computes all it is necessary to initialize the reordering object.
virtual int MaxMyNumEntries() const =0
Returns the maximun number of entries for row.
Ifpack_Graph: a pure virtual class that defines graphs for IFPACK.
virtual ostream & Print(std::ostream &os) const
Prints basic information on iostream. This function is used by operator<<.
virtual int P(const Epetra_MultiVector &Xorig, Epetra_MultiVector &X) const
Applies reordering to multivector Xorig, whose local length equals the number of local rows...