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 options[METIS_NOPTIONS];
00025 mesh_t *mesh;
00026 idx_t *epart, *npart;
00027 idx_t objval;
00028 params_t *params;
00029 int status=0;
00030
00031 params = parse_cmdline(argc, argv);
00032
00033 gk_startcputimer(params->iotimer);
00034 mesh = ReadMesh(params);
00035
00036 if (mesh->ncon > 1) {
00037 printf("*** Meshes with more than one balancing constraint are not supported yet.\n");
00038 exit(0);
00039 }
00040
00041 ReadTPwgts(params, mesh->ncon);
00042 gk_stopcputimer(params->iotimer);
00043
00044 MPPrintInfo(params, mesh);
00045
00046 epart = imalloc(mesh->ne, "main: epart");
00047 npart = imalloc(mesh->nn, "main: npart");
00048
00049 METIS_SetDefaultOptions(options);
00050 options[METIS_OPTION_PTYPE] = params->ptype;
00051 options[METIS_OPTION_OBJTYPE] = params->objtype;
00052 options[METIS_OPTION_CTYPE] = params->ctype;
00053 options[METIS_OPTION_IPTYPE] = params->iptype;
00054 options[METIS_OPTION_RTYPE] = params->rtype;
00055 options[METIS_OPTION_DBGLVL] = params->dbglvl;
00056 options[METIS_OPTION_UFACTOR] = params->ufactor;
00057 options[METIS_OPTION_MINCONN] = params->minconn;
00058 options[METIS_OPTION_CONTIG] = params->contig;
00059 options[METIS_OPTION_SEED] = params->seed;
00060 options[METIS_OPTION_NITER] = params->niter;
00061 options[METIS_OPTION_NCUTS] = params->ncuts;
00062
00063
00064 gk_malloc_init();
00065 gk_startcputimer(params->parttimer);
00066
00067 switch (params->gtype) {
00068 case METIS_GTYPE_DUAL:
00069 status = METIS_PartMeshDual(&mesh->ne, &mesh->nn, mesh->eptr, mesh->eind,
00070 mesh->ewgt, NULL, ¶ms->ncommon, ¶ms->nparts,
00071 params->tpwgts, options, &objval, epart, npart);
00072 break;
00073
00074 case METIS_GTYPE_NODAL:
00075 status = METIS_PartMeshNodal(&mesh->ne, &mesh->nn, mesh->eptr, mesh->eind,
00076 NULL, NULL, ¶ms->nparts, params->tpwgts, options, &objval,
00077 epart, npart);
00078 break;
00079 }
00080
00081 gk_stopcputimer(params->parttimer);
00082 if (gk_GetCurMemoryUsed() != 0)
00083 printf("***It seems that Metis did not free all of its memory! Report this.\n");
00084 params->maxmemory = gk_GetMaxMemoryUsed();
00085 gk_malloc_cleanup(0);
00086
00087 if (status != METIS_OK) {
00088 printf("\n***Metis returned with an error.\n");
00089 }
00090 else {
00091 if (!params->nooutput) {
00092
00093 gk_startcputimer(params->iotimer);
00094 WriteMeshPartition(params->filename, params->nparts, mesh->ne, epart, mesh->nn, npart);
00095 gk_stopcputimer(params->iotimer);
00096 }
00097
00098 MPReportResults(params, mesh, epart, npart, objval);
00099 }
00100
00101 FreeMesh(&mesh);
00102 gk_free((void **)&epart, &npart, LTERM);
00103 gk_free((void **)¶ms->filename, ¶ms->tpwgtsfile, ¶ms->tpwgts,
00104 ¶ms->ubvecstr, ¶ms->ubvec, ¶ms, LTERM);
00105
00106 }
00107
00108
00109
00111
00112 void MPPrintInfo(params_t *params, mesh_t *mesh)
00113 {
00114 if (params->ufactor == -1) {
00115 if (params->ptype == METIS_PTYPE_KWAY)
00116 params->ufactor = KMETIS_DEFAULT_UFACTOR;
00117 else
00118 params->ufactor = PMETIS_DEFAULT_UFACTOR;
00119 }
00120
00121 printf("******************************************************************************\n");
00122 printf("%s", METISTITLE);
00123 printf(" (HEAD: %s, Built on: %s, %s)\n", SVNINFO, __DATE__, __TIME__);
00124 printf(" size of idx_t: %zubits, real_t: %zubits, idx_t *: %zubits\n",
00125 8*sizeof(idx_t), 8*sizeof(real_t), 8*sizeof(idx_t *));
00126 printf("\n");
00127 printf("Mesh Information ------------------------------------------------------------\n");
00128 printf(" Name: %s, #Elements: %"PRIDX", #Nodes: %"PRIDX", #Parts: %"PRIDX"\n",
00129 params->filename, mesh->ne, mesh->nn, params->nparts);
00130 if (mesh->ncon > 1)
00131 printf(" Balancing Constraints: %"PRIDX"\n", mesh->ncon);
00132
00133 printf("\n");
00134 printf("Options ---------------------------------------------------------------------\n");
00135 printf(" ptype=%s, objtype=%s, ctype=%s, rtype=%s, iptype=%s\n",
00136 ptypenames[params->ptype], objtypenames[params->objtype], ctypenames[params->ctype],
00137 rtypenames[params->rtype], iptypenames[params->iptype]);
00138
00139 printf(" dbglvl=%"PRIDX", ufactor=%.3f, minconn=%s, contig=%s, nooutput=%s\n",
00140 params->dbglvl,
00141 I2RUBFACTOR(params->ufactor),
00142 (params->minconn ? "YES" : "NO"),
00143 (params->contig ? "YES" : "NO"),
00144 (params->nooutput ? "YES" : "NO")
00145 );
00146
00147 printf(" seed=%"PRIDX", niter=%"PRIDX", ncuts=%"PRIDX"\n",
00148 params->seed, params->niter, params->ncuts);
00149
00150 printf(" gtype=%s, ncommon=%"PRIDX", niter=%"PRIDX", ncuts=%"PRIDX"\n",
00151 gtypenames[params->gtype], params->ncommon, params->niter, params->ncuts);
00152
00153 printf("\n");
00154 switch (params->ptype) {
00155 case METIS_PTYPE_RB:
00156 printf("Recursive Partitioning ------------------------------------------------------\n");
00157 break;
00158 case METIS_PTYPE_KWAY:
00159 printf("Direct k-way Partitioning ---------------------------------------------------\n");
00160 break;
00161 }
00162 }
00163
00164
00165
00167
00168 void MPReportResults(params_t *params, mesh_t *mesh, idx_t *epart, idx_t *npart,
00169 idx_t objval)
00170 {
00171
00172 gk_startcputimer(params->reporttimer);
00173
00174
00175
00176 printf(" - %s: %"PRIDX".\n\n",
00177 (params->objtype == METIS_OBJTYPE_CUT ? "Edgecut" : "Volume"), objval);
00178
00179 gk_stopcputimer(params->reporttimer);
00180
00181
00182 printf("\nTiming Information ----------------------------------------------------------\n");
00183 printf(" I/O: \t\t %7.3"PRREAL" sec\n", gk_getcputimer(params->iotimer));
00184 printf(" Partitioning: \t\t %7.3"PRREAL" sec (METIS time)\n", gk_getcputimer(params->parttimer));
00185 printf(" Reporting: \t\t %7.3"PRREAL" sec\n", gk_getcputimer(params->reporttimer));
00186 printf("\nMemory Information ----------------------------------------------------------\n");
00187 printf(" Max memory used:\t\t %7.3"PRREAL" MB\n", (real_t)(params->maxmemory/(1024.0*1024.0)));
00188 printf("******************************************************************************\n");
00189
00190 }