00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <metis.h>
00016
00017
00018
00019
00020
00021 void AllocateWorkSpace(CtrlType *ctrl, GraphType *graph, int nparts)
00022 {
00023 memsize_t nedges=graph->nedges;
00024 memsize_t nvtxs=graph->nvtxs;
00025 ctrl->wspace.pmat = NULL;
00026
00027 if (ctrl->optype == OP_KMETIS) {
00028 ctrl->wspace.edegrees = (EDegreeType *)GKmalloc(graph->nedges*sizeof(EDegreeType), "AllocateWorkSpace: edegrees");
00029 ctrl->wspace.vedegrees = NULL;
00030 ctrl->wspace.auxcore = (idxtype *)ctrl->wspace.edegrees;
00031
00032 ctrl->wspace.pmat = idxmalloc(nparts*nparts, "AllocateWorkSpace: pmat");
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 ctrl->wspace.maxcore = 3*(nvtxs+1) +
00048 5*(nparts+1) +
00049 nvtxs*(sizeof(ListNodeType)/sizeof(idxtype)) +
00050 20
00051 ;
00052 }
00053 else if (ctrl->optype == OP_KVMETIS) {
00054 ctrl->wspace.edegrees = NULL;
00055 ctrl->wspace.vedegrees = (VEDegreeType *)GKmalloc(nedges*sizeof(VEDegreeType), "AllocateWorkSpace: vedegrees");
00056 ctrl->wspace.auxcore = (idxtype *)ctrl->wspace.vedegrees;
00057
00058 ctrl->wspace.pmat = idxmalloc(nparts*nparts, "AllocateWorkSpace: pmat");
00059
00060
00061 ctrl->wspace.maxcore = 3*(nvtxs+1) +
00062 3*(nparts+1) +
00063 nvtxs*(sizeof(ListNodeType)/sizeof(idxtype)) +
00064 20
00065 ;
00066 }
00067 else {
00068 ctrl->wspace.edegrees = (EDegreeType *)idxmalloc(nedges, "AllocateWorkSpace: edegrees");
00069 ctrl->wspace.vedegrees = NULL;
00070 ctrl->wspace.auxcore = (idxtype *)ctrl->wspace.edegrees;
00071
00072 ctrl->wspace.maxcore = 5*(nvtxs+1) +
00073 4*(nparts+1) +
00074 2*graph->ncon*nvtxs*(sizeof(ListNodeType)/sizeof(idxtype)) +
00075 2*graph->ncon*(NEG_GAINSPAN+PLUS_GAINSPAN+1)*(sizeof(ListNodeType *)/sizeof(idxtype)) +
00076 20
00077 ;
00078 }
00079
00080 ctrl->wspace.maxcore += HTLENGTH;
00081 ctrl->wspace.core = idxmalloc(ctrl->wspace.maxcore, "AllocateWorkSpace: maxcore");
00082 ctrl->wspace.ccore = 0;
00083 }
00084
00085
00086
00087
00088
00089 void FreeWorkSpace(CtrlType *ctrl, GraphType *graph)
00090 {
00091 GKfree(&ctrl->wspace.edegrees, &ctrl->wspace.vedegrees, &ctrl->wspace.core, &ctrl->wspace.pmat, LTERM);
00092 }
00093
00094
00095
00096
00097 int WspaceAvail(CtrlType *ctrl)
00098 {
00099 return ctrl->wspace.maxcore - ctrl->wspace.ccore;
00100 }
00101
00102
00103
00104
00105
00106 idxtype *idxwspacemalloc(CtrlType *ctrl, memsize_t n)
00107 {
00108 n += n%2;
00109
00110 ctrl->wspace.ccore += n;
00111 ASSERT(ctrl->wspace.ccore <= ctrl->wspace.maxcore);
00112 return ctrl->wspace.core + ctrl->wspace.ccore - n;
00113 }
00114
00115
00116
00117
00118 void idxwspacefree(CtrlType *ctrl, int n)
00119 {
00120 n += n%2;
00121
00122 ctrl->wspace.ccore -= n;
00123 ASSERT(ctrl->wspace.ccore >= 0);
00124 }
00125
00126
00127
00128
00129
00130 floattype *fwspacemalloc(CtrlType *ctrl, memsize_t n)
00131 {
00132 n += n%2;
00133
00134 ctrl->wspace.ccore += n;
00135 ASSERT(ctrl->wspace.ccore <= ctrl->wspace.maxcore);
00136 return (floattype *) (ctrl->wspace.core + ctrl->wspace.ccore - n);
00137 }
00138
00139
00140
00141
00142 void fwspacefree(CtrlType *ctrl, memsize_t n)
00143 {
00144 n += n%2;
00145
00146 ctrl->wspace.ccore -= n;
00147 ASSERT(ctrl->wspace.ccore >= 0);
00148 }
00149
00150
00151
00152
00153
00154
00155
00156 GraphType *CreateGraph(void)
00157 {
00158 GraphType *graph;
00159
00160 graph = (GraphType *)GKmalloc(sizeof(GraphType), "CreateCoarseGraph: graph");
00161
00162 InitGraph(graph);
00163
00164 return graph;
00165 }
00166
00167
00168
00169
00170
00171
00172 void InitGraph(GraphType *graph)
00173 {
00174 graph->gdata = graph->rdata = NULL;
00175
00176 graph->nvtxs = graph->nedges = -1;
00177 graph->mincut = graph->minvol = -1;
00178
00179 graph->xadj = graph->vwgt = graph->adjncy = graph->adjwgt = NULL;
00180 graph->adjwgtsum = NULL;
00181 graph->label = NULL;
00182 graph->cmap = NULL;
00183
00184 graph->where = graph->pwgts = NULL;
00185 graph->id = graph->ed = NULL;
00186 graph->bndptr = graph->bndind = NULL;
00187 graph->rinfo = NULL;
00188 graph->vrinfo = NULL;
00189 graph->nrinfo = NULL;
00190
00191 graph->ncon = -1;
00192 graph->nvwgt = NULL;
00193 graph->npwgts = NULL;
00194
00195 graph->vsize = NULL;
00196
00197 graph->coarser = graph->finer = NULL;
00198
00199 }
00200
00201
00202
00203
00204 void FreeGraph(GraphType *graph)
00205 {
00206
00207 GKfree(&graph->gdata, &graph->nvwgt, &graph->rdata, &graph->npwgts, LTERM);
00208 free(graph);
00209 }
00210