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