| 1 |
/*! |
| 2 |
\file |
| 3 |
\brief Functions dealing with memory allocation and workspace management |
| 4 |
|
| 5 |
\date Started 2/24/96 |
| 6 |
\author George |
| 7 |
\author Copyright 1997-2009, Regents of the University of Minnesota |
| 8 |
\version $Id: wspace.c 10492 2011-07-06 09:28:42Z karypis $ |
| 9 |
*/ |
| 10 |
|
| 11 |
#include "metislib.h" |
| 12 |
|
| 13 |
|
| 14 |
/*************************************************************************/ |
| 15 |
/*! This function allocates memory for the workspace */ |
| 16 |
/*************************************************************************/ |
| 17 |
void AllocateWorkSpace(ctrl_t *ctrl, graph_t *graph) |
| 18 |
{ |
| 19 |
size_t coresize; |
| 20 |
|
| 21 |
switch (ctrl->optype) { |
| 22 |
default: |
| 23 |
coresize = 4*(graph->nvtxs+1)*sizeof(idx_t) + |
| 24 |
5*(ctrl->nparts+1)*graph->ncon*sizeof(idx_t) + |
| 25 |
5*(ctrl->nparts+1)*graph->ncon*sizeof(real_t); |
| 26 |
} |
| 27 |
ctrl->mcore = gk_mcoreCreate(coresize); |
| 28 |
} |
| 29 |
|
| 30 |
/*************************************************************************/ |
| 31 |
/*! This function frees the workspace */ |
| 32 |
/*************************************************************************/ |
| 33 |
void FreeWorkSpace(ctrl_t *ctrl) |
| 34 |
{ |
| 35 |
gk_mcoreDestroy(&ctrl->mcore, ctrl->dbglvl&METIS_DBG_INFO); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
/*************************************************************************/ |
| 40 |
/*! This function allocate space from the workspace/heap */ |
| 41 |
/*************************************************************************/ |
| 42 |
void *wspacemalloc(ctrl_t *ctrl, size_t nbytes) |
| 43 |
{ |
| 44 |
return gk_mcoreMalloc(ctrl->mcore, nbytes); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
/*************************************************************************/ |
| 49 |
/*! This function sets a marker in the stack of malloc ops to be used |
| 50 |
subsequently for freeing purposes */ |
| 51 |
/*************************************************************************/ |
| 52 |
void wspacepush(ctrl_t *ctrl) |
| 53 |
{ |
| 54 |
gk_mcorePush(ctrl->mcore); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
/*************************************************************************/ |
| 59 |
/*! This function frees all mops since the last push */ |
| 60 |
/*************************************************************************/ |
| 61 |
void wspacepop(ctrl_t *ctrl) |
| 62 |
{ |
| 63 |
gk_mcorePop(ctrl->mcore); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
/*************************************************************************/ |
| 68 |
/*! This function allocate space from the core */ |
| 69 |
/*************************************************************************/ |
| 70 |
idx_t *iwspacemalloc(ctrl_t *ctrl, idx_t n) |
| 71 |
{ |
| 72 |
return (idx_t *)wspacemalloc(ctrl, n*sizeof(idx_t)); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
/*************************************************************************/ |
| 77 |
/*! This function allocate space from the core */ |
| 78 |
/*************************************************************************/ |
| 79 |
real_t *rwspacemalloc(ctrl_t *ctrl, idx_t n) |
| 80 |
{ |
| 81 |
return (real_t *)wspacemalloc(ctrl, n*sizeof(real_t)); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
/*************************************************************************/ |
| 86 |
/*! This function allocate space from the core */ |
| 87 |
/*************************************************************************/ |
| 88 |
ikv_t *ikvwspacemalloc(ctrl_t *ctrl, idx_t n) |
| 89 |
{ |
| 90 |
return (ikv_t *)wspacemalloc(ctrl, n*sizeof(ikv_t)); |
| 91 |
} |