43 #include "Ifpack_ConfigDefs.h" 44 #include "Ifpack_Partitioner.h" 45 #include "Ifpack_OverlappingPartitioner.h" 46 #include "Ifpack_LinePartitioner.h" 47 #include "Ifpack_Graph.h" 48 #include "Epetra_Util.h" 51 inline void Ifpack_LinePartitioner::local_automatic_line_search(
int NumEqns,
int * blockIndices,
int last,
int next,
int LineID,
double tol,
int *itemp,
double * dtemp)
const {
52 double *xvals=xcoord_, *yvals=ycoord_, *zvals=zcoord_;
58 int * indices = &itemp[allocated_space];
59 double * dist = dtemp;
62 while (blockIndices[next] == -1) {
65 int neighbors_in_line=0;
68 double x0 = (xvals) ? xvals[next/NumEqns] : 0.0;
69 double y0 = (yvals) ? yvals[next/NumEqns] : 0.0;
70 double z0 = (zvals) ? zvals[next/NumEqns] : 0.0;
74 for(
int i=0; i<n; i+=NumEqns) {
76 if(cols[i] >=N)
continue;
77 int nn = cols[i] / NumEqns;
78 if(blockIndices[nn]==LineID) neighbors_in_line++;
79 if(xvals) mydist += (x0 - xvals[nn]) * (x0 - xvals[nn]);
80 if(yvals) mydist += (y0 - yvals[nn]) * (y0 - yvals[nn]);
81 if(zvals) mydist += (z0 - zvals[nn]) * (z0 - zvals[nn]);
82 dist[neighbor_len] = sqrt(mydist);
83 indices[neighbor_len]=cols[i];
88 if(neighbors_in_line > 1)
break;
91 for(
int k=0; k<NumEqns; k++)
92 blockIndices[next + k] = LineID;
95 Epetra_Util::Sort(
true,neighbor_len,dist,0,0,1,&indices,0,0);
97 if(neighbor_len > 2 && indices[1] != last && blockIndices[indices[1]] == -1 && dist[1]/dist[neighbor_len-1] < tol) {
101 else if(neighbor_len > 3 && indices[2] != last && blockIndices[indices[2]] == -1 && dist[2]/dist[neighbor_len-1] < tol) {
113 int Ifpack_LinePartitioner::Compute_Blocks_AutoLine(
int * blockIndices)
const {
114 double *xvals=xcoord_, *yvals=ycoord_, *zvals=zcoord_;
115 int NumEqns = NumEqns_;
116 double tol = threshold_;
120 int * cols =
new int[2*allocated_space];
121 int * indices = &cols[allocated_space];
122 double * dist =
new double[allocated_space];
124 int * itemp =
new int[2*allocated_space];
125 double *dtemp =
new double[allocated_space];
129 for(
int i=0; i<N; i+=NumEqns) {
132 if(blockIndices[i] !=-1)
continue;
136 double x0 = (xvals) ? xvals[i/NumEqns] : 0.0;
137 double y0 = (yvals) ? yvals[i/NumEqns] : 0.0;
138 double z0 = (zvals) ? zvals[i/NumEqns] : 0.0;
141 for(
int j=0; j<nz; j+=NumEqns) {
143 int nn = cols[j] / NumEqns;
144 if(cols[j] >=N)
continue;
145 if(xvals) mydist += (x0 - xvals[nn]) * (x0 - xvals[nn]);
146 if(yvals) mydist += (y0 - yvals[nn]) * (y0 - yvals[nn]);
147 if(zvals) mydist += (z0 - zvals[nn]) * (z0 - zvals[nn]);
148 dist[neighbor_len] = sqrt(mydist);
149 indices[neighbor_len]=cols[j];
153 Epetra_Util::Sort(
true,neighbor_len,dist,0,0,1,&indices,0,0);
156 for(
int k=0; k<NumEqns; k++)
157 blockIndices[i + k] = num_lines;
160 if(neighbor_len > 2 && dist[1]/dist[neighbor_len-1] < tol) {
161 local_automatic_line_search(NumEqns,blockIndices,i,indices[1],num_lines,tol,itemp,dtemp);
164 if(neighbor_len > 3 && dist[2]/dist[neighbor_len-1] < tol) {
165 local_automatic_line_search(NumEqns,blockIndices,i,indices[2],num_lines,tol,itemp,dtemp);
183 if(!xcoord_ && !ycoord_ && !zcoord_) IFPACK_CHK_ERR(-1);
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 NumMyRows() const
Returns the number of local rows.
std::vector< int > Partition_
Partition_[i] contains the ID of non-overlapping part it belongs to.
int ComputePartitions()
Computes the partitions. Returns 0 if successful.
const Ifpack_Graph * Graph_
Reference to the graph to be partitioned.
int NumLocalParts_
Number of local subgraphs.
std::vector< std::vector< int > > Parts_
Parts_[i][j] is the ID of the j-th row contained in the (overlapping)