00001
00010 #include "metisbin.h"
00011
00012
00013
00014
00015
00016 static struct gk_option long_options[] = {
00017 {"ptype", 1, 0, METIS_OPTION_PTYPE},
00018 {"objtype", 1, 0, METIS_OPTION_OBJTYPE},
00019
00020 {"ctype", 1, 0, METIS_OPTION_CTYPE},
00021 {"iptype", 1, 0, METIS_OPTION_IPTYPE},
00022
00023
00024
00025
00026 {"no2hop", 0, 0, METIS_OPTION_NO2HOP},
00027 {"minconn", 0, 0, METIS_OPTION_MINCONN},
00028 {"contig", 0, 0, METIS_OPTION_CONTIG},
00029
00030 {"nooutput", 0, 0, METIS_OPTION_NOOUTPUT},
00031
00032 {"ufactor", 1, 0, METIS_OPTION_UFACTOR},
00033 {"niter", 1, 0, METIS_OPTION_NITER},
00034 {"ncuts", 1, 0, METIS_OPTION_NCUTS},
00035
00036 {"tpwgts", 1, 0, METIS_OPTION_TPWGTS},
00037 {"ubvec", 1, 0, METIS_OPTION_UBVEC},
00038
00039 {"seed", 1, 0, METIS_OPTION_SEED},
00040
00041 {"dbglvl", 1, 0, METIS_OPTION_DBGLVL},
00042
00043 {"help", 0, 0, METIS_OPTION_HELP},
00044 {0, 0, 0, 0}
00045 };
00046
00047
00048
00049
00050
00051
00052 static gk_StringMap_t ptype_options[] = {
00053 {"rb", METIS_PTYPE_RB},
00054 {"kway", METIS_PTYPE_KWAY},
00055 {NULL, 0}
00056 };
00057
00058 static gk_StringMap_t objtype_options[] = {
00059 {"cut", METIS_OBJTYPE_CUT},
00060 {"vol", METIS_OBJTYPE_VOL},
00061 {NULL, 0}
00062 };
00063
00064 static gk_StringMap_t ctype_options[] = {
00065 {"rm", METIS_CTYPE_RM},
00066 {"shem", METIS_CTYPE_SHEM},
00067 {NULL, 0}
00068 };
00069
00070 static gk_StringMap_t iptype_options[] = {
00071 {"grow", METIS_IPTYPE_GROW},
00072 {"random", METIS_IPTYPE_RANDOM},
00073 {NULL, 0}
00074 };
00075
00076 static gk_StringMap_t rtype_options[] = {
00077 {"fm", METIS_RTYPE_FM},
00078 {"greedy", METIS_RTYPE_GREEDY},
00079 {NULL, 0}
00080 };
00081
00082
00083
00084
00085
00086
00087 static char helpstr[][100] =
00088 {
00089 " ",
00090 "Usage: gpmetis [options] graphfile nparts",
00091 " ",
00092 " Required parameters",
00093 " graphfile Stores the graph to be partitioned.",
00094 " nparts The number of partitions to split the graph.",
00095 " ",
00096 " Optional parameters",
00097 " -ptype=string",
00098 " Specifies the scheme to be used for computing the k-way partitioning.",
00099 " The possible values are:",
00100 " rb - Recursive bisectioning",
00101 " kway - Direct k-way partitioning [default]",
00102 " ",
00103 " -ctype=string",
00104 " Specifies the scheme to be used to match the vertices of the graph",
00105 " during the coarsening.",
00106 " The possible values are:",
00107 " rm - Random matching",
00108 " shem - Sorted heavy-edge matching [default]",
00109 " ",
00110 " -iptype=string [applies only when -ptype=rb]",
00111 " Specifies the scheme to be used to compute the initial partitioning",
00112 " of the graph.",
00113 " The possible values are:",
00114 " grow - Grow a bisection using a greedy scheme [default for ncon=1]",
00115 " random - Compute a bisection at random [default for ncon>1]",
00116 " ",
00117 " -objtype=string [applies only when -ptype=kway]",
00118 " Specifies the objective that the partitioning routines will optimize.",
00119 " The possible values are:",
00120 " cut - Minimize the edgecut [default]",
00121 " vol - Minimize the total communication volume",
00122 " ",
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 " -no2hop",
00133 " Specifies that the coarsening will not perform any 2-hop matchings",
00134 " when the standard matching fails to sufficiently contract the graph.",
00135 " ",
00136 " -contig [applies only when -ptype=kway]",
00137 " Specifies that the partitioning routines should try to produce",
00138 " partitions that are contiguous. Note that if the input graph is not",
00139 " connected this option is ignored.",
00140 " ",
00141 " -minconn [applies only when -ptype=kway]",
00142 " Specifies that the partitioning routines should try to minimize the",
00143 " maximum degree of the subdomain graph, i.e., the graph in which each",
00144 " partition is a node, and edges connect subdomains with a shared",
00145 " interface.",
00146 " ",
00147 " -tpwgts=filename",
00148 " Specifies the name of the file that stores the target weights for",
00149 " each partition. By default, all partitions are assumed to be of ",
00150 " the same size.",
00151 " ",
00152 " -ufactor=int",
00153 " Specifies the maximum allowed load imbalance among the partitions.",
00154 " A value of x indicates that the allowed load imbalance is 1+x/1000.",
00155 " For ptype=rb, the load imbalance is measured as the ratio of the ",
00156 " 2*max(left,right)/(left+right), where left and right are the sizes",
00157 " of the respective partitions at each bisection. ",
00158 " For ptype=kway, the load imbalance is measured as the ratio of ",
00159 " max_i(pwgts[i])/avgpwgt, where pwgts[i] is the weight of the ith",
00160 " partition and avgpwgt is the sum of the total vertex weights divided",
00161 " by the number of partitions requested.",
00162 " For ptype=rb, the default value is 1 (i.e., load imbalance of 1.001).",
00163 " For ptype=kway, the default value is 30 (i.e., load imbalance of 1.03).",
00164 " ",
00165 " -ubvec=string",
00166 " Applies only for multi-constraint partitioning and specifies the per",
00167 " constraint allowed load imbalance among partitions. The required ",
00168 " parameter corresponds to a space separated set of floating point",
00169 " numbers, one for each of the constraints. For example, for three",
00170 " constraints, the string can be \"1.02 1.2 1.35\" indicating a ",
00171 " desired maximum load imbalance of 2%, 20%, and 35%, respectively.",
00172 " The load imbalance is defined in a way similar to ufactor.",
00173 " If supplied, this parameter takes priority over ufactor.",
00174 " ",
00175 " -niter=int",
00176 " Specifies the number of iterations for the refinement algorithms",
00177 " at each stage of the uncoarsening process. Default is 10.",
00178 " ",
00179 " -ncuts=int",
00180 " Specifies the number of different partitionings that it will compute.",
00181 " The final partitioning is the one that achieves the best edgecut or",
00182 " communication volume. Default is 1.",
00183 " ",
00184 " -nooutput",
00185 " Specifies that no partitioning file should be generated.",
00186 " ",
00187
00188
00189
00190
00191
00192
00193
00194 " -seed=int",
00195 " Selects the seed of the random number generator. ",
00196 " ",
00197 " -dbglvl=int ",
00198 " Selects the dbglvl. ",
00199 " ",
00200 " -help",
00201 " Prints this message.",
00202 ""
00203 };
00204
00205 static char shorthelpstr[][100] = {
00206 " ",
00207 " Usage: gpmetis [options] <filename> <nparts>",
00208 " use 'gpmetis -help' for a summary of the options.",
00209 ""
00210 };
00211
00212
00213
00214
00215
00216
00217 params_t *parse_cmdline(int argc, char *argv[])
00218 {
00219 int i, j, k;
00220 int c, option_index;
00221 params_t *params;
00222
00223 params = (params_t *)gk_malloc(sizeof(params_t), "parse_cmdline");
00224 memset((void *)params, 0, sizeof(params_t));
00225
00226
00227 params->ptype = METIS_PTYPE_KWAY;
00228 params->objtype = METIS_OBJTYPE_CUT;
00229 params->ctype = METIS_CTYPE_SHEM;
00230 params->iptype = -1;
00231 params->rtype = -1;
00232
00233 params->no2hop = 0;
00234 params->minconn = 0;
00235 params->contig = 0;
00236
00237 params->nooutput = 0;
00238 params->wgtflag = 3;
00239
00240 params->ncuts = 1;
00241 params->niter = 10;
00242
00243 params->dbglvl = 0;
00244 params->balance = 0;
00245 params->seed = -1;
00246 params->dbglvl = 0;
00247
00248 params->tpwgtsfile = NULL;
00249
00250 params->filename = NULL;
00251 params->nparts = 1;
00252
00253 params->ufactor = -1;
00254
00255 params->ubvecstr = NULL;
00256 params->ubvec = NULL;
00257
00258
00259 gk_clearcputimer(params->iotimer);
00260 gk_clearcputimer(params->parttimer);
00261 gk_clearcputimer(params->reporttimer);
00262
00263
00264
00265 while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) {
00266 switch (c) {
00267 case METIS_OPTION_PTYPE:
00268 if (gk_optarg)
00269 if ((params->ptype = gk_GetStringID(ptype_options, gk_optarg)) == -1)
00270 errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);
00271 break;
00272 case METIS_OPTION_OBJTYPE:
00273 if (gk_optarg)
00274 if ((params->objtype = gk_GetStringID(objtype_options, gk_optarg)) == -1)
00275 errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);
00276 break;
00277 case METIS_OPTION_CTYPE:
00278 if (gk_optarg)
00279 if ((params->ctype = gk_GetStringID(ctype_options, gk_optarg)) == -1)
00280 errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);
00281 break;
00282 case METIS_OPTION_IPTYPE:
00283 if (gk_optarg)
00284 if ((params->iptype = gk_GetStringID(iptype_options, gk_optarg)) == -1)
00285 errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);
00286 break;
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296 case METIS_OPTION_NO2HOP:
00297 params->no2hop = 1;
00298 break;
00299
00300 case METIS_OPTION_CONTIG:
00301 params->contig = 1;
00302 break;
00303
00304 case METIS_OPTION_MINCONN:
00305 params->minconn = 1;
00306 break;
00307
00308 case METIS_OPTION_NOOUTPUT:
00309 params->nooutput = 1;
00310 break;
00311
00312 case METIS_OPTION_BALANCE:
00313 params->balance = 1;
00314 break;
00315
00316 case METIS_OPTION_TPWGTS:
00317 if (gk_optarg) params->tpwgtsfile = gk_strdup(gk_optarg);
00318 break;
00319
00320 case METIS_OPTION_UBVEC:
00321 if (gk_optarg) params->ubvecstr = gk_strdup(gk_optarg);
00322 break;
00323
00324 case METIS_OPTION_NCUTS:
00325 if (gk_optarg) params->ncuts = (idx_t)atoi(gk_optarg);
00326 break;
00327 case METIS_OPTION_NITER:
00328 if (gk_optarg) params->niter = (idx_t)atoi(gk_optarg);
00329 break;
00330
00331 case METIS_OPTION_UFACTOR:
00332 if (gk_optarg) params->ufactor = (idx_t)atoi(gk_optarg);
00333 break;
00334
00335 case METIS_OPTION_SEED:
00336 if (gk_optarg) params->seed = (idx_t)atoi(gk_optarg);
00337 break;
00338
00339 case METIS_OPTION_DBGLVL:
00340 if (gk_optarg) params->dbglvl = (idx_t)atoi(gk_optarg);
00341 break;
00342
00343 case METIS_OPTION_HELP:
00344 for (i=0; strlen(helpstr[i]) > 0; i++)
00345 printf("%s\n", helpstr[i]);
00346 exit(0);
00347 break;
00348 case '?':
00349 default:
00350 errexit("Illegal command-line option(s)\n"
00351 "Use %s -help for a summary of the options.\n", argv[0]);
00352 }
00353 }
00354
00355 if (argc-gk_optind != 2) {
00356 printf("Missing parameters.");
00357 for (i=0; strlen(shorthelpstr[i]) > 0; i++)
00358 printf("%s\n", shorthelpstr[i]);
00359 exit(0);
00360 }
00361
00362 params->filename = gk_strdup(argv[gk_optind++]);
00363 params->nparts = atoi(argv[gk_optind++]);
00364
00365 if (params->nparts < 2)
00366 errexit("The number of partitions should be greater than 1!\n");
00367
00368
00369
00370 if (params->ptype == METIS_PTYPE_RB) {
00371 params->rtype = METIS_RTYPE_FM;
00372 }
00373 if (params->ptype == METIS_PTYPE_KWAY) {
00374 params->iptype = METIS_IPTYPE_METISRB;
00375 params->rtype = METIS_RTYPE_GREEDY;
00376 }
00377
00378
00379 if (params->ptype == METIS_PTYPE_RB) {
00380 if (params->contig)
00381 errexit("***The -contig option cannot be specified with rb partitioning. Will be ignored.\n");
00382 if (params->minconn)
00383 errexit("***The -minconn option cannot be specified with rb partitioning. Will be ignored. \n");
00384 if (params->objtype == METIS_OBJTYPE_VOL)
00385 errexit("The -objtype=vol option cannot be specified with rb partitioning.\n");
00386 }
00387
00388 return params;
00389 }
00390
00391