43 #include "Ifpack_ConfigDefs.h"
44 #include "Ifpack_Partitioner.h"
45 #include "Ifpack_OverlappingPartitioner.h"
46 #include "Ifpack_METISPartitioner.h"
47 #include "Ifpack_Graph.h"
48 #include "Ifpack_Graph_Epetra_CrsGraph.h"
49 #include "Epetra_Comm.h"
50 #include "Epetra_CrsGraph.h"
51 #include "Epetra_Map.h"
52 #include "Teuchos_ParameterList.hpp"
53 #include "Teuchos_RefCountPtr.hpp"
57 #ifdef HAVE_IFPACK_METIS
59 void METIS_EstimateMemory(
int *, idxtype *, idxtype *,
int *,
int *,
int *);
60 void METIS_PartGraphKway(
int *, idxtype *, idxtype *, idxtype *,
61 idxtype *,
int *,
int *,
int *,
int *,
int *,
63 void METIS_PartGraphRecursive(
int *, idxtype *, idxtype *,
64 idxtype *, idxtype *,
int *,
int *,
int *,
65 int *,
int *, idxtype *);
80 #ifdef HAVE_IFPACK_METIS
85 Teuchos::RefCountPtr<Epetra_CrsGraph> SymGraph ;
86 Teuchos::RefCountPtr<Epetra_Map> SymMap;
87 Teuchos::RefCountPtr<Ifpack_Graph_Epetra_CrsGraph> SymIFPACKGraph;
88 Teuchos::RefCountPtr<Ifpack_Graph> IFPACKGraph = Teuchos::rcp( (
Ifpack_Graph*)
Graph_,
false );
93 Indices.resize(Length);
98 vector<idxtype> wgtflag;
106 if (UseSymmetricGraph_) {
113 SymGraph = Teuchos::rcp(
new Epetra_CrsGraph(Copy,*SymMap,0) );
119 IFPACK_CHK_ERR(ierr);
121 for (
int j = 0 ; j < NumIndices ; ++j) {
124 SymGraph->InsertGlobalIndices(i,1,&jj);
125 SymGraph->InsertGlobalIndices(jj,1,&i);
129 IFPACK_CHK_ERR(SymGraph->FillComplete());
131 IFPACKGraph = SymIFPACKGraph;
143 vector<idxtype> xadj;
146 vector<idxtype> adjncy;
155 xadj[count2+1] = xadj[count2];
157 ierr = IFPACKGraph->ExtractMyRowCopy(i, Length, NumIndices, &Indices[0]);
158 IFPACK_CHK_ERR(ierr);
160 for (
int j = 0 ; j < NumIndices ; ++j) {
163 adjncy[count++] = jj;
170 vector<idxtype> NodesInSubgraph;
199 #ifdef HAVE_IFPACK_METIS
205 METIS_EstimateMemory(&j, &xadj[0], &adjncy[0],
206 &numflag, &i, &nbytes );
208 METIS_PartGraphRecursive(&j, &xadj[0], &adjncy[0],
216 METIS_PartGraphKway (&j, &xadj[0], &adjncy[0],
218 NULL, &wgtflag[0], &numflag,
223 numflag = numflag * 2;
225 cerr <<
"METIS was not linked; now I put all" << endl;
226 cerr <<
"the local nodes in the same partition." << endl;
236 NodesInSubgraph[i] = 0;
238 for (
int i = 0 ; i <
NumMyRows() ; ++i) {
244 else NodesInSubgraph[j]++;
248 if( NodesInSubgraph[i] == 0 ) {
255 cerr <<
"Specified number of subgraphs ("
257 cerr <<
"Now I recall METIS with NumLocalParts_ = "
virtual int ExtractMyRowCopy(int MyRow, int LenOfIndices, int &NumIndices, int *Indices) const =0
Extracts a copy of input local row.
int MaxNumEntries() const
Returns the max number of local entries in a row.
int NumMyNonzeros() const
Returns the number of local nonzero elements.
int NumMyRows() const
Returns the number of local rows.
std::vector< int > Partition_
Partition_[i] contains the ID of non-overlapping part it belongs to.
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.
const Ifpack_Graph * Graph_
Reference to the graph to be partitioned.
int NumLocalParts_
Number of local subgraphs.
int NumLocalParts() const
Returns the number of computed local partitions.
Ifpack_Graph: a pure virtual class that defines graphs for IFPACK.
int ComputePartitions()
Computes the partitions. Returns 0 if successful.