00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <metis.h>
00017
00018
00019
00020
00021
00022 void METIS_EstimateMemory(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *optype, int *nbytes)
00023 {
00024 int i, j, k, nedges, nlevels;
00025 floattype vfraction, efraction, vmult, emult;
00026 int coresize, gdata, rdata;
00027
00028 if (*numflag == 1)
00029 Change2CNumbering(*nvtxs, xadj, adjncy);
00030
00031 nedges = xadj[*nvtxs];
00032
00033 InitRandom(-1);
00034 EstimateCFraction(*nvtxs, xadj, adjncy, &vfraction, &efraction);
00035
00036
00037 if (*optype == 2)
00038 coresize = nedges;
00039 else
00040 coresize = 0;
00041 coresize += nedges + 11*(*nvtxs) + 4*1024 + 2*(NEG_GAINSPAN+PLUS_GAINSPAN+1)*(sizeof(ListNodeType *)/sizeof(idxtype));
00042 coresize += 2*(*nvtxs);
00043
00044 gdata = nedges;
00045
00046 nlevels = (int)(log(100.0/(*nvtxs))/log(vfraction) + .5);
00047 vmult = 0.5 + (1.0 - pow(vfraction, nlevels))/(1.0 - vfraction);
00048 emult = 1.0 + (1.0 - pow(efraction, nlevels+1))/(1.0 - efraction);
00049
00050 gdata += vmult*4*(*nvtxs) + emult*2*nedges;
00051 if ((vmult-1.0)*4*(*nvtxs) + (emult-1.0)*2*nedges < 5*(*nvtxs))
00052 rdata = 0;
00053 else
00054 rdata = 5*(*nvtxs);
00055
00056 *nbytes = sizeof(idxtype)*(coresize+gdata+rdata+(*nvtxs));
00057
00058 if (*numflag == 1)
00059 Change2FNumbering2(*nvtxs, xadj, adjncy);
00060 }
00061
00062
00063
00064
00065
00066 void EstimateCFraction(int nvtxs, idxtype *xadj, idxtype *adjncy, floattype *vfraction, floattype *efraction)
00067 {
00068 int i, ii, j, cnvtxs, cnedges, maxidx;
00069 idxtype *match, *cmap, *perm;
00070
00071 cmap = idxmalloc(nvtxs, "cmap");
00072 match = idxsmalloc(nvtxs, UNMATCHED, "match");
00073 perm = idxmalloc(nvtxs, "perm");
00074 RandomPermute(nvtxs, perm, 1);
00075
00076 cnvtxs = 0;
00077 for (ii=0; ii<nvtxs; ii++) {
00078 i = perm[ii];
00079
00080 if (match[i] == UNMATCHED) {
00081 maxidx = i;
00082
00083
00084 for (j=xadj[i]; j<xadj[i+1]; j++) {
00085 if (match[adjncy[j]] == UNMATCHED) {
00086 maxidx = adjncy[j];
00087 break;
00088 }
00089 }
00090
00091 cmap[i] = cmap[maxidx] = cnvtxs++;
00092 match[i] = maxidx;
00093 match[maxidx] = i;
00094 }
00095 }
00096
00097 cnedges = ComputeCoarseGraphSize(nvtxs, xadj, adjncy, cnvtxs, cmap, match, perm);
00098
00099 *vfraction = (1.0*cnvtxs)/(1.0*nvtxs);
00100 *efraction = (1.0*cnedges)/(1.0*xadj[nvtxs]);
00101
00102 GKfree(&cmap, &match, &perm, LTERM);
00103 }
00104
00105
00106
00107
00108
00109
00110
00111 int ComputeCoarseGraphSize(int nvtxs, idxtype *xadj, idxtype *adjncy, int cnvtxs, idxtype *cmap, idxtype *match, idxtype *perm)
00112 {
00113 int i, j, k, istart, iend, nedges, cnedges, v, u;
00114 idxtype *htable;
00115
00116 htable = idxsmalloc(cnvtxs, -1, "htable");
00117
00118 cnvtxs = cnedges = 0;
00119 for (i=0; i<nvtxs; i++) {
00120 v = perm[i];
00121 if (cmap[v] != cnvtxs)
00122 continue;
00123
00124 htable[cnvtxs] = cnvtxs;
00125
00126 u = match[v];
00127
00128 istart = xadj[v];
00129 iend = xadj[v+1];
00130 for (j=istart; j<iend; j++) {
00131 k = cmap[adjncy[j]];
00132 if (htable[k] != cnvtxs) {
00133 htable[k] = cnvtxs;
00134 cnedges++;
00135 }
00136 }
00137
00138 if (v != u) {
00139 istart = xadj[u];
00140 iend = xadj[u+1];
00141 for (j=istart; j<iend; j++) {
00142 k = cmap[adjncy[j]];
00143 if (htable[k] != cnvtxs) {
00144 htable[k] = cnvtxs;
00145 cnedges++;
00146 }
00147 }
00148 }
00149 cnvtxs++;
00150 }
00151
00152 GKfree(&htable, LTERM);
00153
00154 return cnedges;
00155 }
00156
00157