00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "metisbin.h"
00016
00017
00018
00019
00021
00022 int main(int argc, char *argv[])
00023 {
00024 idx_t i;
00025 char *curptr, *newptr;
00026 idx_t options[METIS_NOPTIONS];
00027 graph_t *graph;
00028 idx_t *part;
00029 idx_t objval;
00030 params_t *params;
00031 int status=0;
00032
00033 params = parse_cmdline(argc, argv);
00034
00035 gk_startcputimer(params->iotimer);
00036 graph = ReadGraph(params);
00037
00038 ReadTPwgts(params, graph->ncon);
00039 gk_stopcputimer(params->iotimer);
00040
00041
00042 if (params->contig && !IsConnected(graph, 0)) {
00043 printf("***The input graph is not contiguous.\n"
00044 "***The specified -contig option will be ignored.\n");
00045 params->contig = 0;
00046 }
00047
00048
00049 if (params->ubvecstr) {
00050 params->ubvec = rmalloc(graph->ncon, "main");
00051 curptr = params->ubvecstr;
00052 for (i=0; i<graph->ncon; i++) {
00053 params->ubvec[i] = strtoreal(curptr, &newptr);
00054 if (curptr == newptr)
00055 errexit("Error parsing entry #%"PRIDX" of ubvec [%s] (possibly missing).\n",
00056 i, params->ubvecstr);
00057 curptr = newptr;
00058 }
00059 }
00060
00061
00062 if (params->iptype == -1) {
00063 if (params->ptype == METIS_PTYPE_RB) {
00064 if (graph->ncon == 1)
00065 params->iptype = METIS_IPTYPE_GROW;
00066 else
00067 params->iptype = METIS_IPTYPE_RANDOM;
00068 }
00069 }
00070
00071 GPPrintInfo(params, graph);
00072
00073 part = imalloc(graph->nvtxs, "main: part");
00074
00075 METIS_SetDefaultOptions(options);
00076 options[METIS_OPTION_OBJTYPE] = params->objtype;
00077 options[METIS_OPTION_CTYPE] = params->ctype;
00078 options[METIS_OPTION_IPTYPE] = params->iptype;
00079 options[METIS_OPTION_RTYPE] = params->rtype;
00080 options[METIS_OPTION_NO2HOP] = params->no2hop;
00081 options[METIS_OPTION_MINCONN] = params->minconn;
00082 options[METIS_OPTION_CONTIG] = params->contig;
00083 options[METIS_OPTION_SEED] = params->seed;
00084 options[METIS_OPTION_NITER] = params->niter;
00085 options[METIS_OPTION_NCUTS] = params->ncuts;
00086 options[METIS_OPTION_UFACTOR] = params->ufactor;
00087 options[METIS_OPTION_DBGLVL] = params->dbglvl;
00088
00089 gk_malloc_init();
00090 gk_startcputimer(params->parttimer);
00091
00092 switch (params->ptype) {
00093 case METIS_PTYPE_RB:
00094 status = METIS_PartGraphRecursive(&graph->nvtxs, &graph->ncon, graph->xadj,
00095 graph->adjncy, graph->vwgt, graph->vsize, graph->adjwgt,
00096 ¶ms->nparts, params->tpwgts, params->ubvec, options,
00097 &objval, part);
00098 break;
00099
00100 case METIS_PTYPE_KWAY:
00101 status = METIS_PartGraphKway(&graph->nvtxs, &graph->ncon, graph->xadj,
00102 graph->adjncy, graph->vwgt, graph->vsize, graph->adjwgt,
00103 ¶ms->nparts, params->tpwgts, params->ubvec, options,
00104 &objval, part);
00105 break;
00106
00107 }
00108
00109 gk_stopcputimer(params->parttimer);
00110
00111 if (gk_GetCurMemoryUsed() != 0)
00112 printf("***It seems that Metis did not free all of its memory! Report this.\n");
00113 params->maxmemory = gk_GetMaxMemoryUsed();
00114 gk_malloc_cleanup(0);
00115
00116
00117 if (status != METIS_OK) {
00118 printf("\n***Metis returned with an error.\n");
00119 }
00120 else {
00121 if (!params->nooutput) {
00122
00123 gk_startcputimer(params->iotimer);
00124 WritePartition(params->filename, part, graph->nvtxs, params->nparts);
00125 gk_stopcputimer(params->iotimer);
00126 }
00127
00128 GPReportResults(params, graph, part, objval);
00129 }
00130
00131 FreeGraph(&graph);
00132 gk_free((void **)&part, LTERM);
00133 gk_free((void **)¶ms->filename, ¶ms->tpwgtsfile, ¶ms->tpwgts,
00134 ¶ms->ubvecstr, ¶ms->ubvec, ¶ms, LTERM);
00135
00136 }
00137
00138
00139
00141
00142 void GPPrintInfo(params_t *params, graph_t *graph)
00143 {
00144 idx_t i;
00145
00146 if (params->ufactor == -1) {
00147 if (params->ptype == METIS_PTYPE_KWAY)
00148 params->ufactor = KMETIS_DEFAULT_UFACTOR;
00149 else if (graph->ncon == 1)
00150 params->ufactor = PMETIS_DEFAULT_UFACTOR;
00151 else
00152 params->ufactor = MCPMETIS_DEFAULT_UFACTOR;
00153 }
00154
00155 printf("******************************************************************************\n");
00156 printf("%s", METISTITLE);
00157 printf(" (HEAD: %s, Built on: %s, %s)\n", SVNINFO, __DATE__, __TIME__);
00158 printf(" size of idx_t: %zubits, real_t: %zubits, idx_t *: %zubits\n",
00159 8*sizeof(idx_t), 8*sizeof(real_t), 8*sizeof(idx_t *));
00160 printf("\n");
00161 printf("Graph Information -----------------------------------------------------------\n");
00162 printf(" Name: %s, #Vertices: %"PRIDX", #Edges: %"PRIDX", #Parts: %"PRIDX"\n",
00163 params->filename, graph->nvtxs, graph->nedges/2, params->nparts);
00164 if (graph->ncon > 1)
00165 printf(" Balancing constraints: %"PRIDX"\n", graph->ncon);
00166
00167 printf("\n");
00168 printf("Options ---------------------------------------------------------------------\n");
00169 printf(" ptype=%s, objtype=%s, ctype=%s, rtype=%s, iptype=%s\n",
00170 ptypenames[params->ptype], objtypenames[params->objtype], ctypenames[params->ctype],
00171 rtypenames[params->rtype], iptypenames[params->iptype]);
00172
00173 printf(" dbglvl=%"PRIDX", ufactor=%.3f, no2hop=%s, minconn=%s, contig=%s, nooutput=%s\n",
00174 params->dbglvl,
00175 I2RUBFACTOR(params->ufactor),
00176 (params->no2hop ? "YES" : "NO"),
00177 (params->minconn ? "YES" : "NO"),
00178 (params->contig ? "YES" : "NO"),
00179 (params->nooutput ? "YES" : "NO")
00180 );
00181
00182 printf(" seed=%"PRIDX", niter=%"PRIDX", ncuts=%"PRIDX"\n",
00183 params->seed, params->niter, params->ncuts);
00184
00185 if (params->ubvec) {
00186 printf(" ubvec=(");
00187 for (i=0; i<graph->ncon; i++)
00188 printf("%s%.2e", (i==0?"":" "), (double)params->ubvec[i]);
00189 printf(")\n");
00190 }
00191
00192 printf("\n");
00193 switch (params->ptype) {
00194 case METIS_PTYPE_RB:
00195 printf("Recursive Partitioning ------------------------------------------------------\n");
00196 break;
00197 case METIS_PTYPE_KWAY:
00198 printf("Direct k-way Partitioning ---------------------------------------------------\n");
00199 break;
00200 }
00201 }
00202
00203
00204
00206
00207 void GPReportResults(params_t *params, graph_t *graph, idx_t *part, idx_t objval)
00208 {
00209 gk_startcputimer(params->reporttimer);
00210 ComputePartitionInfo(params, graph, part);
00211
00212 gk_stopcputimer(params->reporttimer);
00213
00214 printf("\nTiming Information ----------------------------------------------------------\n");
00215 printf(" I/O: \t\t %7.3"PRREAL" sec\n", gk_getcputimer(params->iotimer));
00216 printf(" Partitioning: \t\t %7.3"PRREAL" sec (METIS time)\n", gk_getcputimer(params->parttimer));
00217 printf(" Reporting: \t\t %7.3"PRREAL" sec\n", gk_getcputimer(params->reporttimer));
00218 printf("\nMemory Information ----------------------------------------------------------\n");
00219 printf(" Max memory used:\t\t %7.3"PRREAL" MB\n", (real_t)(params->maxmemory/(1024.0*1024.0)));
00220 printf("******************************************************************************\n");
00221
00222 }