00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <metis.h>
00016
00017
00018
00019
00020 int ComputeCut(GraphType *graph, idxtype *where)
00021 {
00022 int i, j, cut;
00023
00024 if (graph->adjwgt == NULL) {
00025 for (cut=0, i=0; i<graph->nvtxs; i++) {
00026 for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++)
00027 if (where[i] != where[graph->adjncy[j]])
00028 cut++;
00029 }
00030 }
00031 else {
00032 for (cut=0, i=0; i<graph->nvtxs; i++) {
00033 for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++)
00034 if (where[i] != where[graph->adjncy[j]])
00035 cut += graph->adjwgt[j];
00036 }
00037 }
00038
00039 return cut/2;
00040 }
00041
00042
00043
00044
00045
00046 int CheckBnd(GraphType *graph)
00047 {
00048 int i, j, nvtxs, nbnd;
00049 idxtype *xadj, *adjncy, *where, *bndptr, *bndind;
00050
00051 nvtxs = graph->nvtxs;
00052 xadj = graph->xadj;
00053 adjncy = graph->adjncy;
00054 where = graph->where;
00055 bndptr = graph->bndptr;
00056 bndind = graph->bndind;
00057
00058 for (nbnd=0, i=0; i<nvtxs; i++) {
00059 if (xadj[i+1]-xadj[i] == 0)
00060 nbnd++;
00061
00062 for (j=xadj[i]; j<xadj[i+1]; j++) {
00063 if (where[i] != where[adjncy[j]]) {
00064 nbnd++;
00065 ASSERT(bndptr[i] != -1);
00066 ASSERT(bndind[bndptr[i]] == i);
00067 break;
00068 }
00069 }
00070 }
00071
00072 ASSERTP(nbnd == graph->nbnd, ("%d %d\n", nbnd, graph->nbnd));
00073
00074 return 1;
00075 }
00076
00077
00078
00079
00080
00081
00082 int CheckBnd2(GraphType *graph)
00083 {
00084 int i, j, nvtxs, nbnd, id, ed;
00085 idxtype *xadj, *adjncy, *where, *bndptr, *bndind;
00086
00087 nvtxs = graph->nvtxs;
00088 xadj = graph->xadj;
00089 adjncy = graph->adjncy;
00090 where = graph->where;
00091 bndptr = graph->bndptr;
00092 bndind = graph->bndind;
00093
00094 for (nbnd=0, i=0; i<nvtxs; i++) {
00095 id = ed = 0;
00096 for (j=xadj[i]; j<xadj[i+1]; j++) {
00097 if (where[i] != where[adjncy[j]])
00098 ed += graph->adjwgt[j];
00099 else
00100 id += graph->adjwgt[j];
00101 }
00102 if (ed - id >= 0 && xadj[i] < xadj[i+1]) {
00103 nbnd++;
00104 ASSERTP(bndptr[i] != -1, ("%d %d %d\n", i, id, ed));
00105 ASSERT(bndind[bndptr[i]] == i);
00106 }
00107 }
00108
00109 ASSERTP(nbnd == graph->nbnd, ("%d %d\n", nbnd, graph->nbnd));
00110
00111 return 1;
00112 }
00113
00114
00115
00116
00117 int CheckNodeBnd(GraphType *graph, int onbnd)
00118 {
00119 int i, j, nvtxs, nbnd;
00120 idxtype *xadj, *adjncy, *where, *bndptr, *bndind;
00121
00122 nvtxs = graph->nvtxs;
00123 xadj = graph->xadj;
00124 adjncy = graph->adjncy;
00125 where = graph->where;
00126 bndptr = graph->bndptr;
00127 bndind = graph->bndind;
00128
00129 for (nbnd=0, i=0; i<nvtxs; i++) {
00130 if (where[i] == 2)
00131 nbnd++;
00132 }
00133
00134 ASSERTP(nbnd == onbnd, ("%d %d\n", nbnd, onbnd));
00135
00136 for (i=0; i<nvtxs; i++) {
00137 if (where[i] != 2) {
00138 ASSERTP(bndptr[i] == -1, ("%d %d\n", i, bndptr[i]));
00139 }
00140 else {
00141 ASSERTP(bndptr[i] != -1, ("%d %d\n", i, bndptr[i]));
00142 }
00143 }
00144
00145 return 1;
00146 }
00147
00148
00149
00150
00151
00152
00153 int CheckRInfo(RInfoType *rinfo)
00154 {
00155 int i, j;
00156
00157 for (i=0; i<rinfo->ndegrees; i++) {
00158 for (j=i+1; j<rinfo->ndegrees; j++)
00159 ASSERTP(rinfo->edegrees[i].pid != rinfo->edegrees[j].pid, ("%d %d %d %d\n", i, j, rinfo->edegrees[i].pid, rinfo->edegrees[j].pid));
00160 }
00161
00162 return 1;
00163 }
00164
00165
00166
00167
00168
00169
00170 int CheckNodePartitionParams(GraphType *graph)
00171 {
00172 int i, j, k, l, nvtxs, me, other;
00173 idxtype *xadj, *adjncy, *adjwgt, *vwgt, *where;
00174 idxtype edegrees[2], pwgts[3];
00175
00176 nvtxs = graph->nvtxs;
00177 xadj = graph->xadj;
00178 vwgt = graph->vwgt;
00179 adjncy = graph->adjncy;
00180 adjwgt = graph->adjwgt;
00181
00182 where = graph->where;
00183
00184
00185
00186
00187 pwgts[0] = pwgts[1] = pwgts[2] = 0;
00188 for (i=0; i<nvtxs; i++) {
00189 me = where[i];
00190 pwgts[me] += vwgt[i];
00191
00192 if (me == 2) {
00193 edegrees[0] = edegrees[1] = 0;
00194
00195 for (j=xadj[i]; j<xadj[i+1]; j++) {
00196 other = where[adjncy[j]];
00197 if (other != 2)
00198 edegrees[other] += vwgt[adjncy[j]];
00199 }
00200 if (edegrees[0] != graph->nrinfo[i].edegrees[0] || edegrees[1] != graph->nrinfo[i].edegrees[1]) {
00201 printf("Something wrong with edegrees: %d %d %d %d %d\n", i, edegrees[0], edegrees[1], graph->nrinfo[i].edegrees[0], graph->nrinfo[i].edegrees[1]);
00202 return 0;
00203 }
00204 }
00205 }
00206
00207 if (pwgts[0] != graph->pwgts[0] || pwgts[1] != graph->pwgts[1] || pwgts[2] != graph->pwgts[2])
00208 printf("Something wrong with part-weights: %d %d %d %d %d %d\n", pwgts[0], pwgts[1], pwgts[2], graph->pwgts[0], graph->pwgts[1], graph->pwgts[2]);
00209
00210 return 1;
00211 }
00212
00213
00214
00215
00216
00217 int IsSeparable(GraphType *graph)
00218 {
00219 int i, j, nvtxs, other;
00220 idxtype *xadj, *adjncy, *where;
00221
00222 nvtxs = graph->nvtxs;
00223 xadj = graph->xadj;
00224 adjncy = graph->adjncy;
00225 where = graph->where;
00226
00227 for (i=0; i<nvtxs; i++) {
00228 if (where[i] == 2)
00229 continue;
00230 other = (where[i]+1)%2;
00231 for (j=xadj[i]; j<xadj[i+1]; j++) {
00232 ASSERTP(where[adjncy[j]] != other, ("%d %d %d %d %d %d\n", i, where[i], adjncy[j], where[adjncy[j]], xadj[i+1]-xadj[i], xadj[adjncy[j]+1]-xadj[adjncy[j]]));
00233 }
00234 }
00235
00236 return 1;
00237 }
00238
00239