1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
/*
* Copyright 1997, Regents of the University of Minnesota
*
* memory.c
*
* This file contains routines that deal with memory allocation
*
* Started 2/24/96
* George
*
* $Id: memory.c,v 1.3 2003/07/30 18:37:59 karypis Exp $
*
*/
#include <parmetislib.h>
/*************************************************************************
* This function allocate various pools of memory
**************************************************************************/
void PreAllocateMemory(CtrlType *ctrl, GraphType *graph, WorkSpaceType *wspace)
{
wspace->nlarge = 2*graph->nedges;
wspace->maxcore = 8*graph->nedges+1;
wspace->core = idxmalloc(wspace->maxcore, "PreAllocateMemory: wspace->core");
wspace->pairs = (KeyValueType *)wspace->core;
wspace->indices = (idxtype *)(wspace->pairs + wspace->nlarge);
wspace->degrees = (EdgeType *)(wspace->indices + wspace->nlarge);
wspace->pv1 = idxmalloc(ctrl->nparts+ctrl->npes+1, "PreAllocateMemory: wspace->pv?");
wspace->pv2 = idxmalloc(ctrl->nparts+ctrl->npes+1, "PreAllocateMemory: wspace->pv?");
wspace->pv3 = idxmalloc(ctrl->nparts+ctrl->npes+1, "PreAllocateMemory: wspace->pv?");
wspace->pv4 = idxmalloc(ctrl->nparts+ctrl->npes+1, "PreAllocateMemory: wspace->pv?");
wspace->pepairs1 = (KeyValueType *)GKmalloc(sizeof(KeyValueType)*(ctrl->nparts+ctrl->npes+1), "PreAllocateMemory: wspace->pepairs?");
wspace->pepairs2 = (KeyValueType *)GKmalloc(sizeof(KeyValueType)*(ctrl->nparts+ctrl->npes+1), "PreAllocateMemory: wspace->pepairs?");
}
/*************************************************************************
* This function de-allocate various pools of memory
**************************************************************************/
void FreeWSpace(WorkSpaceType *wspace)
{
GKfree((void **)&wspace->core,
(void **)&wspace->pv1,
(void **)&wspace->pv2,
(void **)&wspace->pv3,
(void **)&wspace->pv4,
(void **)&wspace->pepairs1,
(void **)&wspace->pepairs2,
LTERM);
}
/*************************************************************************
* This function de-allocates memory allocated for the control structures
**************************************************************************/
void FreeCtrl(CtrlType *ctrl)
{
MPI_Comm_free(&(ctrl->gcomm));
}
/*************************************************************************
* This function creates a CoarseGraphType data structure and initializes
* the various fields
**************************************************************************/
GraphType *CreateGraph(void)
{
GraphType *graph;
graph = (GraphType *)GKmalloc(sizeof(GraphType), "CreateCoarseGraph: graph");
InitGraph(graph);
return graph;
}
/*************************************************************************
* This function creates a CoarseGraphType data structure and initializes
* the various fields
**************************************************************************/
void InitGraph(GraphType *graph)
{
graph->gnvtxs = graph->nvtxs = graph->nedges = graph->nsep = -1;
graph->nnbrs = graph->nrecv = graph->nsend = graph->nlocal = -1;
graph->xadj = graph->vwgt = graph->vsize = graph->adjncy = graph->adjwgt = NULL;
graph->nvwgt = NULL;
graph->vtxdist = NULL;
graph->match = graph->cmap = NULL;
graph->label = NULL;
graph->peind = NULL;
graph->sendptr = graph->sendind = graph->recvptr = graph->recvind = NULL;
graph->imap = NULL;
graph->pexadj = graph->peadjncy = graph->peadjloc = NULL;
graph->lperm = NULL;
graph->slens = graph->rlens = NULL;
graph->rcand = NULL;
graph->where = graph->home = graph->lpwgts = graph->gpwgts = NULL;
graph->lnpwgts = graph->gnpwgts = NULL;
graph->rinfo = NULL;
graph->nrinfo = NULL;
graph->sepind = NULL;
graph->coarser = graph->finer = NULL;
}
/*************************************************************************
* This function deallocates any memory stored in a graph
**************************************************************************/
void FreeGraph(GraphType *graph)
{
GKfree((void **)&graph->xadj,
(void **)&graph->vwgt,
(void **)&graph->nvwgt,
(void **)&graph->vsize,
(void **)&graph->adjncy,
(void **)&graph->adjwgt,
(void **)&graph->vtxdist,
(void **)&graph->match,
(void **)&graph->cmap,
(void **)&graph->lperm,
(void **)&graph->label,
(void **)&graph->where,
(void **)&graph->home,
(void **)&graph->rinfo,
(void **)&graph->nrinfo,
(void **)&graph->sepind,
(void **)&graph->lpwgts,
(void **)&graph->gpwgts,
(void **)&graph->lnpwgts,
(void **)&graph->gnpwgts,
(void **)&graph->peind,
(void **)&graph->sendptr,
(void **)&graph->sendind,
(void **)&graph->recvptr,
(void **)&graph->recvind,
(void **)&graph->imap,
(void **)&graph->rlens,
(void **)&graph->slens,
(void **)&graph->rcand,
(void **)&graph->pexadj,
(void **)&graph->peadjncy,
(void **)&graph->peadjloc,
LTERM);
free(graph);
}
/*************************************************************************
* This function deallocates any memory stored in a graph
**************************************************************************/
void FreeInitialGraphAndRemap(GraphType *graph, int wgtflag)
{
int i, nedges;
idxtype *adjncy, *imap;
nedges = graph->nedges;
adjncy = graph->adjncy;
imap = graph->imap;
if (imap != NULL) {
for (i=0; i<nedges; i++)
adjncy[i] = imap[adjncy[i]]; /* Apply local to global transformation */
}
/* Free Metis's things */
GKfree((void **)&graph->match,
(void **)&graph->cmap,
(void **)&graph->lperm,
(void **)&graph->where,
(void **)&graph->label,
(void **)&graph->rinfo,
(void **)&graph->nrinfo,
(void **)&graph->nvwgt,
(void **)&graph->lpwgts,
(void **)&graph->gpwgts,
(void **)&graph->lnpwgts,
(void **)&graph->gnpwgts,
(void **)&graph->sepind,
(void **)&graph->peind,
(void **)&graph->sendptr,
(void **)&graph->sendind,
(void **)&graph->recvptr,
(void **)&graph->recvind,
(void **)&graph->imap,
(void **)&graph->rlens,
(void **)&graph->slens,
(void **)&graph->rcand,
(void **)&graph->pexadj,
(void **)&graph->peadjncy,
(void **)&graph->peadjloc,
LTERM);
if ((wgtflag&2) == 0)
GKfree((void **)&graph->vwgt, (void **)&graph->vsize, LTERM);
if ((wgtflag&1) == 0)
GKfree((void **)&graph->adjwgt, LTERM);
free(graph);
}
|