00001
00011 #include "metislib.h"
00012
00013
00014
00016
00017 void AllocateWorkSpace(ctrl_t *ctrl, graph_t *graph)
00018 {
00019 size_t coresize;
00020
00021 switch (ctrl->optype) {
00022 case METIS_OP_PMETIS:
00023 coresize = 3*(graph->nvtxs+1)*sizeof(idx_t) +
00024 5*(ctrl->nparts+1)*graph->ncon*sizeof(idx_t) +
00025 5*(ctrl->nparts+1)*graph->ncon*sizeof(real_t);
00026 break;
00027 default:
00028 coresize = 4*(graph->nvtxs+1)*sizeof(idx_t) +
00029 5*(ctrl->nparts+1)*graph->ncon*sizeof(idx_t) +
00030 5*(ctrl->nparts+1)*graph->ncon*sizeof(real_t);
00031 }
00032
00033 ctrl->mcore = gk_mcoreCreate(coresize);
00034
00035 ctrl->nbrpoolsize = 0;
00036 ctrl->nbrpoolcpos = 0;
00037 }
00038
00039
00040
00042
00043 void AllocateRefinementWorkSpace(ctrl_t *ctrl, idx_t nbrpoolsize)
00044 {
00045 ctrl->nbrpoolsize = nbrpoolsize;
00046 ctrl->nbrpoolcpos = 0;
00047 ctrl->nbrpoolreallocs = 0;
00048
00049 switch (ctrl->objtype) {
00050 case METIS_OBJTYPE_CUT:
00051 ctrl->cnbrpool = (cnbr_t *)gk_malloc(ctrl->nbrpoolsize*sizeof(cnbr_t),
00052 "AllocateRefinementWorkSpace: cnbrpool");
00053 break;
00054
00055 case METIS_OBJTYPE_VOL:
00056 ctrl->vnbrpool = (vnbr_t *)gk_malloc(ctrl->nbrpoolsize*sizeof(vnbr_t),
00057 "AllocateRefinementWorkSpace: vnbrpool");
00058 break;
00059
00060 default:
00061 gk_errexit(SIGERR, "Unknown objtype of %d\n", ctrl->objtype);
00062 }
00063
00064
00065
00066 if (ctrl->minconn) {
00067 ctrl->pvec1 = imalloc(ctrl->nparts+1, "AllocateRefinementWorkSpace: pvec1");
00068 ctrl->pvec2 = imalloc(ctrl->nparts+1, "AllocateRefinementWorkSpace: pvec2");
00069 ctrl->maxnads = ismalloc(ctrl->nparts, INIT_MAXNAD, "AllocateRefinementWorkSpace: maxnads");
00070 ctrl->nads = imalloc(ctrl->nparts, "AllocateRefinementWorkSpace: nads");
00071 ctrl->adids = iAllocMatrix(ctrl->nparts, INIT_MAXNAD, 0, "AllocateRefinementWorkSpace: adids");
00072 ctrl->adwgts = iAllocMatrix(ctrl->nparts, INIT_MAXNAD, 0, "AllocateRefinementWorkSpace: adwgts");
00073 }
00074 }
00075
00076
00077
00079
00080 void FreeWorkSpace(ctrl_t *ctrl)
00081 {
00082 gk_mcoreDestroy(&ctrl->mcore, ctrl->dbglvl&METIS_DBG_INFO);
00083
00084 IFSET(ctrl->dbglvl, METIS_DBG_INFO,
00085 printf(" nbrpool statistics\n"
00086 " nbrpoolsize: %12zu nbrpoolcpos: %12zu\n"
00087 " nbrpoolreallocs: %12zu\n\n",
00088 ctrl->nbrpoolsize, ctrl->nbrpoolcpos,
00089 ctrl->nbrpoolreallocs));
00090
00091 gk_free((void **)&ctrl->cnbrpool, &ctrl->vnbrpool, LTERM);
00092 ctrl->nbrpoolsize = 0;
00093 ctrl->nbrpoolcpos = 0;
00094
00095 if (ctrl->minconn) {
00096 iFreeMatrix(&(ctrl->adids), ctrl->nparts, INIT_MAXNAD);
00097 iFreeMatrix(&(ctrl->adwgts), ctrl->nparts, INIT_MAXNAD);
00098
00099 gk_free((void **)&ctrl->pvec1, &ctrl->pvec2,
00100 &ctrl->maxnads, &ctrl->nads, LTERM);
00101 }
00102 }
00103
00104
00105
00107
00108 void *wspacemalloc(ctrl_t *ctrl, size_t nbytes)
00109 {
00110 return gk_mcoreMalloc(ctrl->mcore, nbytes);
00111 }
00112
00113
00114
00117
00118 void wspacepush(ctrl_t *ctrl)
00119 {
00120 gk_mcorePush(ctrl->mcore);
00121 }
00122
00123
00124
00126
00127 void wspacepop(ctrl_t *ctrl)
00128 {
00129 gk_mcorePop(ctrl->mcore);
00130 }
00131
00132
00133
00135
00136 idx_t *iwspacemalloc(ctrl_t *ctrl, idx_t n)
00137 {
00138 return (idx_t *)wspacemalloc(ctrl, n*sizeof(idx_t));
00139 }
00140
00141
00142
00144
00145 real_t *rwspacemalloc(ctrl_t *ctrl, idx_t n)
00146 {
00147 return (real_t *)wspacemalloc(ctrl, n*sizeof(real_t));
00148 }
00149
00150
00151
00153
00154 ikv_t *ikvwspacemalloc(ctrl_t *ctrl, idx_t n)
00155 {
00156 return (ikv_t *)wspacemalloc(ctrl, n*sizeof(ikv_t));
00157 }
00158
00159
00160
00162
00163 void cnbrpoolReset(ctrl_t *ctrl)
00164 {
00165 ctrl->nbrpoolcpos = 0;
00166 }
00167
00168
00169
00171
00172 idx_t cnbrpoolGetNext(ctrl_t *ctrl, idx_t nnbrs)
00173 {
00174 ctrl->nbrpoolcpos += nnbrs;
00175
00176 if (ctrl->nbrpoolcpos > ctrl->nbrpoolsize) {
00177 ctrl->nbrpoolsize += gk_max(10*nnbrs, ctrl->nbrpoolsize/2);
00178
00179 ctrl->cnbrpool = (cnbr_t *)gk_realloc(ctrl->cnbrpool,
00180 ctrl->nbrpoolsize*sizeof(cnbr_t), "cnbrpoolGet: cnbrpool");
00181 ctrl->nbrpoolreallocs++;
00182 }
00183
00184 return ctrl->nbrpoolcpos - nnbrs;
00185 }
00186
00187
00188
00190
00191 void vnbrpoolReset(ctrl_t *ctrl)
00192 {
00193 ctrl->nbrpoolcpos = 0;
00194 }
00195
00196
00197
00199
00200 idx_t vnbrpoolGetNext(ctrl_t *ctrl, idx_t nnbrs)
00201 {
00202 ctrl->nbrpoolcpos += nnbrs;
00203
00204 if (ctrl->nbrpoolcpos > ctrl->nbrpoolsize) {
00205 ctrl->nbrpoolsize += gk_max(10*nnbrs, ctrl->nbrpoolsize/2);
00206
00207 ctrl->vnbrpool = (vnbr_t *)gk_realloc(ctrl->vnbrpool,
00208 ctrl->nbrpoolsize*sizeof(vnbr_t), "vnbrpoolGet: vnbrpool");
00209 ctrl->nbrpoolreallocs++;
00210 }
00211
00212 return ctrl->nbrpoolcpos - nnbrs;
00213 }
00214