00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <parmetislib.h>
00016
00017
00018
00019
00020
00021 void PreAllocateMemory(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace)
00022 {
00023 wspace->nlarge = 2*graph->nedges;
00024
00025 wspace->maxcore = 8*graph->nedges+1;
00026 wspace->core = idxmalloc(wspace->maxcore, "PreAllocateMemory: wspace->core");
00027
00028 wspace->pairs = (KeyValueType *)wspace->core;
00029 wspace->indices = (idxtype *)(wspace->pairs + wspace->nlarge);
00030 wspace->degrees = (EdgeType *)(wspace->indices + wspace->nlarge);
00031
00032
00033 wspace->pv1 = idxmalloc(ctrl->nparts+ctrl->npes+1, "PreAllocateMemory: wspace->pv?");
00034 wspace->pv2 = idxmalloc(ctrl->nparts+ctrl->npes+1, "PreAllocateMemory: wspace->pv?");
00035 wspace->pv3 = idxmalloc(ctrl->nparts+ctrl->npes+1, "PreAllocateMemory: wspace->pv?");
00036 wspace->pv4 = idxmalloc(ctrl->nparts+ctrl->npes+1, "PreAllocateMemory: wspace->pv?");
00037
00038 wspace->pepairs1 = (KeyValueType *)GKmalloc(sizeof(KeyValueType)*(ctrl->nparts+ctrl->npes+1), "PreAllocateMemory: wspace->pepairs?");
00039 wspace->pepairs2 = (KeyValueType *)GKmalloc(sizeof(KeyValueType)*(ctrl->nparts+ctrl->npes+1), "PreAllocateMemory: wspace->pepairs?");
00040
00041 }
00042
00043
00044
00045
00046
00047 void FreeWSpace(WorkSpaceType *wspace)
00048 {
00049
00050 GKfree((void **)&wspace->core,
00051 (void **)&wspace->pv1,
00052 (void **)&wspace->pv2,
00053 (void **)&wspace->pv3,
00054 (void **)&wspace->pv4,
00055 (void **)&wspace->pepairs1,
00056 (void **)&wspace->pepairs2,
00057 LTERM);
00058 }
00059
00060
00061
00062
00063
00064 void FreeCtrl(CtrlType *ctrl)
00065 {
00066 MPI_Comm_free(&(ctrl->gcomm));
00067 }
00068
00069
00070
00071
00072
00073
00074 GraphType *CreateGraph(void)
00075 {
00076 GraphType *graph;
00077
00078 graph = (GraphType *)GKmalloc(sizeof(GraphType), "CreateCoarseGraph: graph");
00079
00080 InitGraph(graph);
00081
00082 return graph;
00083 }
00084
00085
00086
00087
00088
00089
00090 void InitGraph(GraphType *graph)
00091 {
00092 graph->gnvtxs = graph->nvtxs = graph->nedges = graph->nsep = -1;
00093 graph->nnbrs = graph->nrecv = graph->nsend = graph->nlocal = -1;
00094 graph->xadj = graph->vwgt = graph->vsize = graph->adjncy = graph->adjwgt = NULL;
00095 graph->nvwgt = NULL;
00096 graph->vtxdist = NULL;
00097 graph->match = graph->cmap = NULL;
00098 graph->label = NULL;
00099
00100 graph->peind = NULL;
00101 graph->sendptr = graph->sendind = graph->recvptr = graph->recvind = NULL;
00102 graph->imap = NULL;
00103 graph->pexadj = graph->peadjncy = graph->peadjloc = NULL;
00104 graph->lperm = NULL;
00105
00106 graph->slens = graph->rlens = NULL;
00107 graph->rcand = NULL;
00108
00109 graph->where = graph->home = graph->lpwgts = graph->gpwgts = NULL;
00110 graph->lnpwgts = graph->gnpwgts = NULL;
00111 graph->rinfo = NULL;
00112
00113 graph->nrinfo = NULL;
00114 graph->sepind = NULL;
00115
00116 graph->coarser = graph->finer = NULL;
00117
00118 }
00119
00120
00121
00122
00123 void FreeGraph(GraphType *graph)
00124 {
00125
00126 GKfree((void **)&graph->xadj,
00127 (void **)&graph->vwgt,
00128 (void **)&graph->nvwgt,
00129 (void **)&graph->vsize,
00130 (void **)&graph->adjncy,
00131 (void **)&graph->adjwgt,
00132 (void **)&graph->vtxdist,
00133 (void **)&graph->match,
00134 (void **)&graph->cmap,
00135 (void **)&graph->lperm,
00136 (void **)&graph->label,
00137 (void **)&graph->where,
00138 (void **)&graph->home,
00139 (void **)&graph->rinfo,
00140 (void **)&graph->nrinfo,
00141 (void **)&graph->sepind,
00142 (void **)&graph->lpwgts,
00143 (void **)&graph->gpwgts,
00144 (void **)&graph->lnpwgts,
00145 (void **)&graph->gnpwgts,
00146 (void **)&graph->peind,
00147 (void **)&graph->sendptr,
00148 (void **)&graph->sendind,
00149 (void **)&graph->recvptr,
00150 (void **)&graph->recvind,
00151 (void **)&graph->imap,
00152 (void **)&graph->rlens,
00153 (void **)&graph->slens,
00154 (void **)&graph->rcand,
00155 (void **)&graph->pexadj,
00156 (void **)&graph->peadjncy,
00157 (void **)&graph->peadjloc,
00158 LTERM);
00159
00160 free(graph);
00161 }
00162
00163
00164
00165
00166
00167
00168 void FreeInitialGraphAndRemap(GraphType *graph, int wgtflag)
00169 {
00170 int i, nedges;
00171 idxtype *adjncy, *imap;
00172
00173 nedges = graph->nedges;
00174 adjncy = graph->adjncy;
00175 imap = graph->imap;
00176
00177 if (imap != NULL) {
00178 for (i=0; i<nedges; i++)
00179 adjncy[i] = imap[adjncy[i]];
00180 }
00181
00182
00183 GKfree((void **)&graph->match,
00184 (void **)&graph->cmap,
00185 (void **)&graph->lperm,
00186 (void **)&graph->where,
00187 (void **)&graph->label,
00188 (void **)&graph->rinfo,
00189 (void **)&graph->nrinfo,
00190 (void **)&graph->nvwgt,
00191 (void **)&graph->lpwgts,
00192 (void **)&graph->gpwgts,
00193 (void **)&graph->lnpwgts,
00194 (void **)&graph->gnpwgts,
00195 (void **)&graph->sepind,
00196 (void **)&graph->peind,
00197 (void **)&graph->sendptr,
00198 (void **)&graph->sendind,
00199 (void **)&graph->recvptr,
00200 (void **)&graph->recvind,
00201 (void **)&graph->imap,
00202 (void **)&graph->rlens,
00203 (void **)&graph->slens,
00204 (void **)&graph->rcand,
00205 (void **)&graph->pexadj,
00206 (void **)&graph->peadjncy,
00207 (void **)&graph->peadjloc,
00208 LTERM);
00209
00210 if ((wgtflag&2) == 0)
00211 GKfree((void **)&graph->vwgt, (void **)&graph->vsize, LTERM);
00212 if ((wgtflag&1) == 0)
00213 GKfree((void **)&graph->adjwgt, LTERM);
00214
00215 free(graph);
00216 }