gpmetis.c
Go to the documentation of this file.
1 /*
2  * Copyright 1994-2011, Regents of the University of Minnesota
3  *
4  * gpmetis.c
5  *
6  * Drivers for the partitioning routines
7  *
8  * Started 8/28/94
9  * George
10  *
11  * $Id: gpmetis.c 13900 2013-03-24 15:27:07Z karypis $
12  *
13  */
14 
15 #include "metisbin.h"
16 
17 
18 
19 /*************************************************************************/
21 /*************************************************************************/
22 int main(int argc, char *argv[])
23 {
24  idx_t i;
25  char *curptr, *newptr;
27  graph_t *graph;
28  idx_t *part;
29  idx_t objval;
31  int status=0;
32 
33  params = parse_cmdline(argc, argv);
34 
35  gk_startcputimer(params->iotimer);
37 
38  ReadTPwgts(params, graph->ncon);
39  gk_stopcputimer(params->iotimer);
40 
41  /* Check if the graph is contiguous */
42  if (params->contig && !IsConnected(graph, 0)) {
43  printf("***The input graph is not contiguous.\n"
44  "***The specified -contig option will be ignored.\n");
45  params->contig = 0;
46  }
47 
48  /* Get ubvec if supplied */
49  if (params->ubvecstr) {
50  params->ubvec = rmalloc(graph->ncon, "main");
51  curptr = params->ubvecstr;
52  for (i=0; i<graph->ncon; i++) {
53  params->ubvec[i] = strtoreal(curptr, &newptr);
54  if (curptr == newptr)
55  errexit("Error parsing entry #%"PRIDX" of ubvec [%s] (possibly missing).\n",
56  i, params->ubvecstr);
57  curptr = newptr;
58  }
59  }
60 
61  /* Setup iptype */
62  if (params->iptype == -1) {
63  if (params->ptype == METIS_PTYPE_RB) {
64  if (graph->ncon == 1)
65  params->iptype = METIS_IPTYPE_GROW;
66  else
67  params->iptype = METIS_IPTYPE_RANDOM;
68  }
69  }
70 
72 
73  part = imalloc(graph->nvtxs, "main: part");
74 
88 
90  gk_startcputimer(params->parttimer);
91 
92  switch (params->ptype) {
93  case METIS_PTYPE_RB:
94  status = METIS_PartGraphRecursive(&graph->nvtxs, &graph->ncon, graph->xadj,
95  graph->adjncy, graph->vwgt, graph->vsize, graph->adjwgt,
96  &params->nparts, params->tpwgts, params->ubvec, options,
97  &objval, part);
98  break;
99 
100  case METIS_PTYPE_KWAY:
101  status = METIS_PartGraphKway(&graph->nvtxs, &graph->ncon, graph->xadj,
102  graph->adjncy, graph->vwgt, graph->vsize, graph->adjwgt,
103  &params->nparts, params->tpwgts, params->ubvec, options,
104  &objval, part);
105  break;
106 
107  }
108 
109  gk_stopcputimer(params->parttimer);
110 
111  if (gk_GetCurMemoryUsed() != 0)
112  printf("***It seems that Metis did not free all of its memory! Report this.\n");
113  params->maxmemory = gk_GetMaxMemoryUsed();
115 
116 
117  if (status != METIS_OK) {
118  printf("\n***Metis returned with an error.\n");
119  }
120  else {
121  if (!params->nooutput) {
122  /* Write the solution */
123  gk_startcputimer(params->iotimer);
124  WritePartition(params->filename, part, graph->nvtxs, params->nparts);
125  gk_stopcputimer(params->iotimer);
126  }
127 
129  }
130 
131  FreeGraph(&graph);
132  gk_free((void **)&part, LTERM);
133  gk_free((void **)&params->filename, &params->tpwgtsfile, &params->tpwgts,
134  &params->ubvecstr, &params->ubvec, &params, LTERM);
135 
136 }
137 
138 
139 /*************************************************************************/
141 /*************************************************************************/
143 {
144  idx_t i;
145 
146  if (params->ufactor == -1) {
147  if (params->ptype == METIS_PTYPE_KWAY)
148  params->ufactor = KMETIS_DEFAULT_UFACTOR;
149  else if (graph->ncon == 1)
150  params->ufactor = PMETIS_DEFAULT_UFACTOR;
151  else
152  params->ufactor = MCPMETIS_DEFAULT_UFACTOR;
153  }
154 
155  printf("******************************************************************************\n");
156  printf("%s", METISTITLE);
157  printf(" (HEAD: %s, Built on: %s, %s)\n", SVNINFO, __DATE__, __TIME__);
158  printf(" size of idx_t: %zubits, real_t: %zubits, idx_t *: %zubits\n",
159  8*sizeof(idx_t), 8*sizeof(real_t), 8*sizeof(idx_t *));
160  printf("\n");
161  printf("Graph Information -----------------------------------------------------------\n");
162  printf(" Name: %s, #Vertices: %"PRIDX", #Edges: %"PRIDX", #Parts: %"PRIDX"\n",
163  params->filename, graph->nvtxs, graph->nedges/2, params->nparts);
164  if (graph->ncon > 1)
165  printf(" Balancing constraints: %"PRIDX"\n", graph->ncon);
166 
167  printf("\n");
168  printf("Options ---------------------------------------------------------------------\n");
169  printf(" ptype=%s, objtype=%s, ctype=%s, rtype=%s, iptype=%s\n",
170  ptypenames[params->ptype], objtypenames[params->objtype], ctypenames[params->ctype],
171  rtypenames[params->rtype], iptypenames[params->iptype]);
172 
173  printf(" dbglvl=%"PRIDX", ufactor=%.3f, no2hop=%s, minconn=%s, contig=%s, nooutput=%s\n",
174  params->dbglvl,
175  I2RUBFACTOR(params->ufactor),
176  (params->no2hop ? "YES" : "NO"),
177  (params->minconn ? "YES" : "NO"),
178  (params->contig ? "YES" : "NO"),
179  (params->nooutput ? "YES" : "NO")
180  );
181 
182  printf(" seed=%"PRIDX", niter=%"PRIDX", ncuts=%"PRIDX"\n",
183  params->seed, params->niter, params->ncuts);
184 
185  if (params->ubvec) {
186  printf(" ubvec=(");
187  for (i=0; i<graph->ncon; i++)
188  printf("%s%.2e", (i==0?"":" "), (double)params->ubvec[i]);
189  printf(")\n");
190  }
191 
192  printf("\n");
193  switch (params->ptype) {
194  case METIS_PTYPE_RB:
195  printf("Recursive Partitioning ------------------------------------------------------\n");
196  break;
197  case METIS_PTYPE_KWAY:
198  printf("Direct k-way Partitioning ---------------------------------------------------\n");
199  break;
200  }
201 }
202 
203 
204 /*************************************************************************/
206 /*************************************************************************/
208 {
209  gk_startcputimer(params->reporttimer);
211 
212  gk_stopcputimer(params->reporttimer);
213 
214  printf("\nTiming Information ----------------------------------------------------------\n");
215  printf(" I/O: \t\t %7.3"PRREAL" sec\n", gk_getcputimer(params->iotimer));
216  printf(" Partitioning: \t\t %7.3"PRREAL" sec (METIS time)\n", gk_getcputimer(params->parttimer));
217  printf(" Reporting: \t\t %7.3"PRREAL" sec\n", gk_getcputimer(params->reporttimer));
218  printf("\nMemory Information ----------------------------------------------------------\n");
219  printf(" Max memory used:\t\t %7.3"PRREAL" MB\n", (real_t)(params->maxmemory/(1024.0*1024.0)));
220  printf("******************************************************************************\n");
221 
222 }
I2RUBFACTOR
#define I2RUBFACTOR(ufactor)
Definition: metis/libmetis/macros.h:35
objval
idx_t idx_t idx_t idx_t idx_t idx_t real_t idx_t idx_t * objval
Definition: include/metis.h:215
METIS_OPTION_UFACTOR
@ METIS_OPTION_UFACTOR
Definition: include/metis.h:287
METIS_OPTION_SEED
@ METIS_OPTION_SEED
Definition: include/metis.h:279
strtoreal
#define strtoreal
Definition: include/metis.h:146
iptypenames
static char iptypenames[][15]
Definition: programs/defs.h:56
METIS_OPTION_OBJTYPE
@ METIS_OPTION_OBJTYPE
Definition: include/metis.h:272
gk_free
void gk_free(void **ptr1,...)
Definition: memory.c:202
METIS_PartGraphRecursive
int METIS_PartGraphRecursive(idx_t *nvtxs, idx_t *ncon, idx_t *xadj, idx_t *adjncy, idx_t *vwgt, idx_t *vsize, idx_t *adjwgt, idx_t *nparts, real_t *tpwgts, real_t *ubvec, idx_t *options, idx_t *objval, idx_t *part)
Recursive partitioning routine.
Definition: pmetis.c:91
gk_getcputimer
#define gk_getcputimer(tmr)
Definition: gk_macros.h:35
imalloc
#define imalloc
Definition: gklib_rename.h:42
errexit
void errexit(char *f_str,...)
Definition: error.c:53
KMETIS_DEFAULT_UFACTOR
#define KMETIS_DEFAULT_UFACTOR
Definition: libmetis/defs.h:54
params_t
Definition: fis.c:15
METIS_PTYPE_RB
@ METIS_PTYPE_RB
Definition: include/metis.h:303
PRREAL
#define PRREAL
Definition: include/metis.h:135
vanilla::params
static const SmartProjectionParams params
Definition: smartFactorScenarios.h:69
ReadGraph
graph_t * ReadGraph(params_t *params)
Definition: programs/io.c:22
METIS_OPTION_NITER
@ METIS_OPTION_NITER
Definition: include/metis.h:277
METIS_PartGraphKway
int METIS_PartGraphKway(idx_t *nvtxs, idx_t *ncon, idx_t *xadj, idx_t *adjncy, idx_t *vwgt, idx_t *vsize, idx_t *adjwgt, idx_t *nparts, real_t *tpwgts, real_t *ubvec, idx_t *options, idx_t *objval, idx_t *part)
Definition: kmetis.c:18
IsConnected
#define IsConnected
Definition: rename.h:54
METIS_OPTION_IPTYPE
@ METIS_OPTION_IPTYPE
Definition: include/metis.h:274
METIS_OPTION_CTYPE
@ METIS_OPTION_CTYPE
Definition: include/metis.h:273
gk_startcputimer
#define gk_startcputimer(tmr)
Definition: gk_macros.h:33
METIS_IPTYPE_GROW
@ METIS_IPTYPE_GROW
Definition: include/metis.h:321
METIS_OK
@ METIS_OK
Definition: include/metis.h:254
ctypenames
static char ctypenames[][15]
Definition: programs/defs.h:50
metisbin.h
GPPrintInfo
void GPPrintInfo(params_t *params, graph_t *graph)
Definition: gpmetis.c:142
rtypenames
static char rtypenames[][15]
Definition: programs/defs.h:53
LTERM
#define LTERM
Definition: gk_defs.h:14
gk_GetMaxMemoryUsed
size_t gk_GetMaxMemoryUsed()
Definition: memory.c:246
METIS_OPTION_CONTIG
@ METIS_OPTION_CONTIG
Definition: include/metis.h:282
main
int main(int argc, char *argv[])
Definition: gpmetis.c:22
METIS_PTYPE_KWAY
@ METIS_PTYPE_KWAY
Definition: include/metis.h:304
METIS_OPTION_DBGLVL
@ METIS_OPTION_DBGLVL
Definition: include/metis.h:276
part
idx_t idx_t idx_t idx_t idx_t idx_t idx_t real_t real_t idx_t idx_t idx_t * part
Definition: include/metis.h:200
METIS_OPTION_RTYPE
@ METIS_OPTION_RTYPE
Definition: include/metis.h:275
parse_cmdline
params_t * parse_cmdline(int argc, char *argv[])
Definition: fis.c:194
ReadTPwgts
void ReadTPwgts(params_t *params, idx_t ncon)
Definition: programs/io.c:275
GPReportResults
void GPReportResults(params_t *params, graph_t *graph, idx_t *part, idx_t objval)
Definition: gpmetis.c:207
METIS_SetDefaultOptions
int METIS_SetDefaultOptions(idx_t *options)
Definition: auxapi.c:36
objtypenames
static char objtypenames[][15]
Definition: programs/defs.h:47
PMETIS_DEFAULT_UFACTOR
#define PMETIS_DEFAULT_UFACTOR
Definition: libmetis/defs.h:52
METIS_OPTION_MINCONN
@ METIS_OPTION_MINCONN
Definition: include/metis.h:281
FreeGraph
#define FreeGraph
Definition: rename.h:98
METIS_IPTYPE_RANDOM
@ METIS_IPTYPE_RANDOM
Definition: include/metis.h:322
METISTITLE
#define METISTITLE
Definition: libmetis/defs.h:18
PRIDX
#define PRIDX
Definition: include/metis.h:107
ptypenames
static char ptypenames[][15]
Definition: programs/defs.h:44
real_t
float real_t
Definition: include/metis.h:132
METIS_NOPTIONS
#define METIS_NOPTIONS
Definition: include/metis.h:175
METIS_OPTION_NO2HOP
@ METIS_OPTION_NO2HOP
Definition: include/metis.h:280
ComputePartitionInfo
void ComputePartitionInfo(params_t *params, graph_t *graph, idx_t *where)
Definition: programs/stat.c:20
graph
NonlinearFactorGraph graph
Definition: doc/Code/OdometryExample.cpp:2
rmalloc
#define rmalloc
Definition: gklib_rename.h:93
gk_GetCurMemoryUsed
size_t gk_GetCurMemoryUsed()
Definition: memory.c:233
gk_stopcputimer
#define gk_stopcputimer(tmr)
Definition: gk_macros.h:34
options
Definition: options.h:16
gk_malloc_cleanup
void gk_malloc_cleanup(int showstats)
Definition: memory.c:118
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
METIS_OPTION_NCUTS
@ METIS_OPTION_NCUTS
Definition: include/metis.h:278
WritePartition
void WritePartition(char *fname, idx_t *part, idx_t n, idx_t nparts)
Definition: programs/io.c:425
graph_t
Definition: libmetis/struct.h:82
MCPMETIS_DEFAULT_UFACTOR
#define MCPMETIS_DEFAULT_UFACTOR
Definition: libmetis/defs.h:53
idx_t
int32_t idx_t
Definition: include/metis.h:101
gk_malloc_init
int gk_malloc_init()
Definition: memory.c:99


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:38