1 /*
2  * Copyright 2001, Regents of the University of Minnesota
3  *
4  * setup.c
5  *
6  * This file contains setup functions for mgridgen
7  *
8  * George Irene
9  */
10 
11 #include "mgridgen.h"
12 
13 
14 /*************************************************************************
15 * This function sets up the graph from the user input
16 **************************************************************************/
SetUpGraph(GraphType * graph,int nvtxs,idxtype * xadj,realtype * vvol,realtype * vsurf,idxtype * adjncy,realtype * adjwgt)17 void SetUpGraph(GraphType *graph, int nvtxs, idxtype *xadj, realtype *vvol,
18                 realtype *vsurf, idxtype *adjncy, realtype *adjwgt)
19 {
20   int i, j;
21 
22   graph->nvtxs     = nvtxs;
23   graph->xadj      = idxmalloc(nvtxs+1, "xadj");
24   graph->vwgt      = idxsmalloc(nvtxs, 1, "vwgt");
25   graph->vvol      = realmalloc(nvtxs, "vvol");
26   graph->vsurf     = realmalloc(nvtxs, "vsurf");
27   graph->adjncy    = idxmalloc(xadj[nvtxs], "adjncy");
28   graph->adjwgt    = realmalloc(xadj[nvtxs], "adjwgt");
29   graph->adjwgtsum = realsmalloc(nvtxs, 0.0, "adjwgtsum");
30 
31   graph->pwgts = NULL;
32   graph->pvol = NULL;
33   graph->psurf = NULL;
34 
35   idxcopy(nvtxs+1, xadj, graph->xadj);
36   realcopy(nvtxs, vvol, graph->vvol);
37   realcopy(nvtxs, vsurf, graph->vsurf);
38   idxcopy(xadj[nvtxs], adjncy, graph->adjncy);
39   realcopy(xadj[nvtxs], adjwgt, graph->adjwgt);
40 
41   for (i=0; i<nvtxs; i++)
42      for (j=xadj[i]; j<xadj[i+1]; j++)
43         graph->adjwgtsum[i] += adjwgt[j];
44 }
45 
46 
47 /*************************************************************************
48 * This function frees the memory that was allocated for the graph
49 **************************************************************************/
FreeGraph(GraphType * graph)50 void FreeGraph(GraphType *graph)
51 {
52   IMfree(&graph->xadj, &graph->vwgt, &graph->vvol, &graph->vsurf,
53               &graph->adjncy, &graph->adjwgt, &graph->adjwgtsum, &graph->cmap,
54               &graph->where, &graph->pwgts, &graph->pvol, &graph->psurf, LTERM);
55 
56 }
57 
58 
59 /*************************************************************************
60 * This function creates a CoarseGraphType data structure and initializes
61 * the various fields
62 **************************************************************************/
CreateGraph(void)63 GraphType *CreateGraph(void)
64 {
65   GraphType *graph;
66 
67   graph = (GraphType *)IMmalloc(sizeof(GraphType), "CreateGraph: graph");
68 
69   graph->nvtxs = -1;
70   graph->nmoves = -1;
71   graph->xadj = NULL;
72   graph->vwgt = NULL;
73   graph->vvol = NULL;
74   graph->vsurf = NULL;
75   graph->adjncy = NULL;
76   graph->adjwgt = NULL;
77   graph->adjwgtsum = NULL;
78   graph->cmap = NULL;
79   graph->where = NULL;
80   graph->pwgts = NULL;
81   graph->pvol = NULL;
82   graph->psurf = NULL;
83 
84   return graph;
85 }
86