00001
00014 #include "metisbin.h"
00015
00016
00017
00019
00020 void ComputePartitionInfo(params_t *params, graph_t *graph, idx_t *where)
00021 {
00022 idx_t i, ii, j, k, nvtxs, ncon, nparts, tvwgt;
00023 idx_t *xadj, *adjncy, *vwgt, *adjwgt, *kpwgts;
00024 real_t *tpwgts, unbalance;
00025 idx_t pid, ndom, maxndom, minndom, tndom, *pptr, *pind, *pdom;
00026 idx_t ncmps, nover, *cptr, *cind, *cpwgts;
00027
00028 nvtxs = graph->nvtxs;
00029 ncon = graph->ncon;
00030 xadj = graph->xadj;
00031 adjncy = graph->adjncy;
00032 vwgt = graph->vwgt;
00033 adjwgt = graph->adjwgt;
00034
00035 nparts = params->nparts;
00036 tpwgts = params->tpwgts;
00037
00038
00039 printf(" - Edgecut: %"PRIDX", communication volume: %"PRIDX".\n\n",
00040 ComputeCut(graph, where), ComputeVolume(graph, where));
00041
00042
00043
00044 kpwgts = ismalloc(ncon*nparts, 0, "ComputePartitionInfo: kpwgts");
00045
00046 for (i=0; i<nvtxs; i++) {
00047 for (j=0; j<ncon; j++)
00048 kpwgts[where[i]*ncon+j] += vwgt[i*ncon+j];
00049 }
00050
00051
00052 printf(" - Balance:\n");
00053 for (j=0; j<ncon; j++) {
00054 tvwgt = isum(nparts, kpwgts+j, ncon);
00055 for (k=0, unbalance=1.0*kpwgts[k*ncon+j]/(tpwgts[k*ncon+j]*tvwgt), i=1; i<nparts; i++) {
00056 if (unbalance < 1.0*kpwgts[i*ncon+j]/(tpwgts[i*ncon+j]*tvwgt)) {
00057 unbalance = 1.0*kpwgts[i*ncon+j]/(tpwgts[i*ncon+j]*tvwgt);
00058 k = i;
00059 }
00060 }
00061 printf(" constraint #%"PRIDX": %5.3"PRREAL" out of %5.3"PRREAL"\n",
00062 j, unbalance,
00063 1.0*nparts*vwgt[ncon*iargmax_strd(nvtxs, vwgt+j, ncon)+j]/
00064 (1.0*isum(nparts, kpwgts+j, ncon)));
00065 }
00066 printf("\n");
00067
00068 if (ncon == 1) {
00069 tvwgt = isum(nparts, kpwgts, 1);
00070 for (k=0, unbalance=kpwgts[k]/(tpwgts[k]*tvwgt), i=1; i<nparts; i++) {
00071 if (unbalance < kpwgts[i]/(tpwgts[i]*tvwgt)) {
00072 unbalance = kpwgts[i]/(tpwgts[i]*tvwgt);
00073 k = i;
00074 }
00075 }
00076
00077 printf(" - Most overweight partition:\n"
00078 " pid: %"PRIDX", actual: %"PRIDX", desired: %"PRIDX", ratio: %.2"PRREAL".\n\n",
00079 k, kpwgts[k], (idx_t)(tvwgt*tpwgts[k]), unbalance);
00080 }
00081
00082 gk_free((void **)&kpwgts, LTERM);
00083
00084
00085
00086 pptr = imalloc(nparts+1, "ComputePartitionInfo: pptr");
00087 pind = imalloc(nvtxs, "ComputePartitionInfo: pind");
00088 pdom = imalloc(nparts, "ComputePartitionInfo: pdom");
00089
00090 iarray2csr(nvtxs, nparts, where, pptr, pind);
00091
00092 maxndom = nparts+1;
00093 minndom = 0;
00094 for (tndom=0, pid=0; pid<nparts; pid++) {
00095 iset(nparts, 0, pdom);
00096 for (ii=pptr[pid]; ii<pptr[pid+1]; ii++) {
00097 i = pind[ii];
00098 for (j=xadj[i]; j<xadj[i+1]; j++)
00099 pdom[where[adjncy[j]]] += adjwgt[j];
00100 }
00101 pdom[pid] = 0;
00102 for (ndom=0, i=0; i<nparts; i++)
00103 ndom += (pdom[i] > 0 ? 1 : 0);
00104 tndom += ndom;
00105 if (pid == 0 || maxndom < ndom)
00106 maxndom = ndom;
00107 if (pid == 0 || minndom > ndom)
00108 minndom = ndom;
00109 }
00110
00111 printf(" - Subdomain connectivity: max: %"PRIDX", min: %"PRIDX", avg: %.2"PRREAL"\n\n",
00112 maxndom, minndom, 1.0*tndom/nparts);
00113
00114 gk_free((void **)&pptr, &pind, &pdom, LTERM);
00115
00116
00117
00118 cptr = imalloc(nvtxs+1, "ComputePartitionInfo: cptr");
00119 cind = imalloc(nvtxs, "ComputePartitionInfo: cind");
00120 cpwgts = ismalloc(nparts, 0, "ComputePartitionInfo: cpwgts");
00121
00122 ncmps = FindPartitionInducedComponents(graph, where, cptr, cind);
00123 if (ncmps == nparts)
00124 printf(" - Each partition is contiguous.\n");
00125 else {
00126 if (IsConnected(graph, 0)) {
00127 for (nover=0, i=0; i<ncmps; i++) {
00128 cpwgts[where[cind[cptr[i]]]]++;
00129 if (cpwgts[where[cind[cptr[i]]]] == 2)
00130 nover++;
00131 }
00132 printf(" - There are %"PRIDX" non-contiguous partitions.\n"
00133 " Total components after removing the cut edges: %"PRIDX",\n"
00134 " max components: %"PRIDX" for pid: %"PRIDX".\n",
00135 nover, ncmps, imax(nparts, cpwgts), (idx_t)iargmax(nparts, cpwgts));
00136 }
00137 else {
00138 printf(" - The original graph had %"PRIDX" connected components and the resulting\n"
00139 " partitioning after removing the cut edges has %"PRIDX" components.",
00140 FindPartitionInducedComponents(graph, NULL, NULL, NULL), ncmps);
00141 }
00142 }
00143
00144 gk_free((void **)&cptr, &cind, &cpwgts, LTERM);
00145
00146 }
00147
00148