Path: blob/devel/elmergrid/src/metis-5.1.0/programs/cmdline_gpmetis.c
3206 views
/*!1\file cmdline_gpmetis.c2\brief Command-line argument parsing for gpmetis34\date 12/24/20085\author George6\version\verbatim $Id: cmdline_gpmetis.c 13901 2013-03-24 16:17:03Z karypis $\endverbatim7*/89#include "metisbin.h"101112/*-------------------------------------------------------------------13* Command-line options14*-------------------------------------------------------------------*/15static struct gk_option long_options[] = {16{"ptype", 1, 0, METIS_OPTION_PTYPE},17{"objtype", 1, 0, METIS_OPTION_OBJTYPE},1819{"ctype", 1, 0, METIS_OPTION_CTYPE},20{"iptype", 1, 0, METIS_OPTION_IPTYPE},21/* {"rtype", 1, 0, METIS_OPTION_RTYPE}, */2223/* {"balanced", 0, 0, METIS_OPTION_BALANCE}, */2425{"no2hop", 0, 0, METIS_OPTION_NO2HOP},26{"minconn", 0, 0, METIS_OPTION_MINCONN},27{"contig", 0, 0, METIS_OPTION_CONTIG},2829{"nooutput", 0, 0, METIS_OPTION_NOOUTPUT},3031{"ufactor", 1, 0, METIS_OPTION_UFACTOR},32{"niter", 1, 0, METIS_OPTION_NITER},33{"ncuts", 1, 0, METIS_OPTION_NCUTS},3435{"tpwgts", 1, 0, METIS_OPTION_TPWGTS},36{"ubvec", 1, 0, METIS_OPTION_UBVEC},3738{"seed", 1, 0, METIS_OPTION_SEED},3940{"dbglvl", 1, 0, METIS_OPTION_DBGLVL},4142{"help", 0, 0, METIS_OPTION_HELP},43{0, 0, 0, 0}44};45464748/*-------------------------------------------------------------------49* Mappings for the various parameter values50*-------------------------------------------------------------------*/51static gk_StringMap_t ptype_options[] = {52{"rb", METIS_PTYPE_RB},53{"kway", METIS_PTYPE_KWAY},54{NULL, 0}55};5657static gk_StringMap_t objtype_options[] = {58{"cut", METIS_OBJTYPE_CUT},59{"vol", METIS_OBJTYPE_VOL},60{NULL, 0}61};6263static gk_StringMap_t ctype_options[] = {64{"rm", METIS_CTYPE_RM},65{"shem", METIS_CTYPE_SHEM},66{NULL, 0}67};6869static gk_StringMap_t iptype_options[] = {70{"grow", METIS_IPTYPE_GROW},71{"random", METIS_IPTYPE_RANDOM},72{NULL, 0}73};7475static gk_StringMap_t rtype_options[] = {76{"fm", METIS_RTYPE_FM},77{"greedy", METIS_RTYPE_GREEDY},78{NULL, 0}79};80818283/*-------------------------------------------------------------------84* Mini help85*-------------------------------------------------------------------*/86static char helpstr[][100] =87{88" ",89"Usage: gpmetis [options] graphfile nparts",90" ",91" Required parameters",92" graphfile Stores the graph to be partitioned.",93" nparts The number of partitions to split the graph.",94" ",95" Optional parameters",96" -ptype=string",97" Specifies the scheme to be used for computing the k-way partitioning.",98" The possible values are:",99" rb - Recursive bisectioning",100" kway - Direct k-way partitioning [default]",101" ",102" -ctype=string",103" Specifies the scheme to be used to match the vertices of the graph",104" during the coarsening.",105" The possible values are:",106" rm - Random matching",107" shem - Sorted heavy-edge matching [default]",108" ",109" -iptype=string [applies only when -ptype=rb]",110" Specifies the scheme to be used to compute the initial partitioning",111" of the graph.",112" The possible values are:",113" grow - Grow a bisection using a greedy scheme [default for ncon=1]",114" random - Compute a bisection at random [default for ncon>1]",115" ",116" -objtype=string [applies only when -ptype=kway]",117" Specifies the objective that the partitioning routines will optimize.",118" The possible values are:",119" cut - Minimize the edgecut [default]",120" vol - Minimize the total communication volume",121" ",122/*123" -rtype=string",124" Specifies the scheme to be used for refinement.",125" The possible values are:",126" fm - 2-way FM refinement [default for -ptype=rb]",127" random - Random k-way refinement",128" greedy - Greedy k-way refinement [default for -ptype=kway]",129" ",130*/131" -no2hop",132" Specifies that the coarsening will not perform any 2-hop matchings",133" when the standard matching fails to sufficiently contract the graph.",134" ",135" -contig [applies only when -ptype=kway]",136" Specifies that the partitioning routines should try to produce",137" partitions that are contiguous. Note that if the input graph is not",138" connected this option is ignored.",139" ",140" -minconn [applies only when -ptype=kway]",141" Specifies that the partitioning routines should try to minimize the",142" maximum degree of the subdomain graph, i.e., the graph in which each",143" partition is a node, and edges connect subdomains with a shared",144" interface.",145" ",146" -tpwgts=filename",147" Specifies the name of the file that stores the target weights for",148" each partition. By default, all partitions are assumed to be of ",149" the same size.",150" ",151" -ufactor=int",152" Specifies the maximum allowed load imbalance among the partitions.",153" A value of x indicates that the allowed load imbalance is 1+x/1000.",154" For ptype=rb, the load imbalance is measured as the ratio of the ",155" 2*max(left,right)/(left+right), where left and right are the sizes",156" of the respective partitions at each bisection. ",157" For ptype=kway, the load imbalance is measured as the ratio of ",158" max_i(pwgts[i])/avgpwgt, where pwgts[i] is the weight of the ith",159" partition and avgpwgt is the sum of the total vertex weights divided",160" by the number of partitions requested.",161" For ptype=rb, the default value is 1 (i.e., load imbalance of 1.001).",162" For ptype=kway, the default value is 30 (i.e., load imbalance of 1.03).",163" ",164" -ubvec=string",165" Applies only for multi-constraint partitioning and specifies the per",166" constraint allowed load imbalance among partitions. The required ",167" parameter corresponds to a space separated set of floating point",168" numbers, one for each of the constraints. For example, for three",169" constraints, the string can be \"1.02 1.2 1.35\" indicating a ",170" desired maximum load imbalance of 2%, 20%, and 35%, respectively.",171" The load imbalance is defined in a way similar to ufactor.",172" If supplied, this parameter takes priority over ufactor.",173" ",174" -niter=int",175" Specifies the number of iterations for the refinement algorithms",176" at each stage of the uncoarsening process. Default is 10.",177" ",178" -ncuts=int",179" Specifies the number of different partitionings that it will compute.",180" The final partitioning is the one that achieves the best edgecut or",181" communication volume. Default is 1.",182" ",183" -nooutput",184" Specifies that no partitioning file should be generated.",185" ",186/*187" -balance",188" Specifies that the final partitioning should contain nparts-1 equal",189" size partitions with the last partition having upto nparts-1 fewer",190" vertices.",191" ",192*/193" -seed=int",194" Selects the seed of the random number generator. ",195" ",196" -dbglvl=int ",197" Selects the dbglvl. ",198" ",199" -help",200" Prints this message.",201""202};203204static char shorthelpstr[][100] = {205" ",206" Usage: gpmetis [options] <filename> <nparts>",207" use 'gpmetis -help' for a summary of the options.",208""209};210211212213/*************************************************************************214* This is the entry point of the command-line argument parser215**************************************************************************/216params_t *parse_cmdline(int argc, char *argv[])217{218int i, j, k;219int c, option_index;220params_t *params;221222params = (params_t *)gk_malloc(sizeof(params_t), "parse_cmdline");223memset((void *)params, 0, sizeof(params_t));224225/* initialize the params data structure */226params->ptype = METIS_PTYPE_KWAY;227params->objtype = METIS_OBJTYPE_CUT;228params->ctype = METIS_CTYPE_SHEM;229params->iptype = -1;230params->rtype = -1;231232params->no2hop = 0;233params->minconn = 0;234params->contig = 0;235236params->nooutput = 0;237params->wgtflag = 3;238239params->ncuts = 1;240params->niter = 10;241242params->dbglvl = 0;243params->balance = 0;244params->seed = -1;245params->dbglvl = 0;246247params->tpwgtsfile = NULL;248249params->filename = NULL;250params->nparts = 1;251252params->ufactor = -1;253254params->ubvecstr = NULL;255params->ubvec = NULL;256257258gk_clearcputimer(params->iotimer);259gk_clearcputimer(params->parttimer);260gk_clearcputimer(params->reporttimer);261262263/* Parse the command line arguments */264while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) {265switch (c) {266case METIS_OPTION_PTYPE:267if (gk_optarg)268if ((params->ptype = gk_GetStringID(ptype_options, gk_optarg)) == -1)269errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);270break;271case METIS_OPTION_OBJTYPE:272if (gk_optarg)273if ((params->objtype = gk_GetStringID(objtype_options, gk_optarg)) == -1)274errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);275break;276case METIS_OPTION_CTYPE:277if (gk_optarg)278if ((params->ctype = gk_GetStringID(ctype_options, gk_optarg)) == -1)279errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);280break;281case METIS_OPTION_IPTYPE:282if (gk_optarg)283if ((params->iptype = gk_GetStringID(iptype_options, gk_optarg)) == -1)284errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);285break;286287/*288case METIS_OPTION_RTYPE:289if (gk_optarg)290if ((params->rtype = gk_GetStringID(rtype_options, gk_optarg)) == -1)291errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);292break;293*/294295case METIS_OPTION_NO2HOP:296params->no2hop = 1;297break;298299case METIS_OPTION_CONTIG:300params->contig = 1;301break;302303case METIS_OPTION_MINCONN:304params->minconn = 1;305break;306307case METIS_OPTION_NOOUTPUT:308params->nooutput = 1;309break;310311case METIS_OPTION_BALANCE:312params->balance = 1;313break;314315case METIS_OPTION_TPWGTS:316if (gk_optarg) params->tpwgtsfile = gk_strdup(gk_optarg);317break;318319case METIS_OPTION_UBVEC:320if (gk_optarg) params->ubvecstr = gk_strdup(gk_optarg);321break;322323case METIS_OPTION_NCUTS:324if (gk_optarg) params->ncuts = (idx_t)atoi(gk_optarg);325break;326case METIS_OPTION_NITER:327if (gk_optarg) params->niter = (idx_t)atoi(gk_optarg);328break;329330case METIS_OPTION_UFACTOR:331if (gk_optarg) params->ufactor = (idx_t)atoi(gk_optarg);332break;333334case METIS_OPTION_SEED:335if (gk_optarg) params->seed = (idx_t)atoi(gk_optarg);336break;337338case METIS_OPTION_DBGLVL:339if (gk_optarg) params->dbglvl = (idx_t)atoi(gk_optarg);340break;341342case METIS_OPTION_HELP:343for (i=0; strlen(helpstr[i]) > 0; i++)344printf("%s\n", helpstr[i]);345exit(0);346break;347case '?':348default:349errexit("Illegal command-line option(s)\n"350"Use %s -help for a summary of the options.\n", argv[0]);351}352}353354if (argc-gk_optind != 2) {355printf("Missing parameters.");356for (i=0; strlen(shorthelpstr[i]) > 0; i++)357printf("%s\n", shorthelpstr[i]);358exit(0);359}360361params->filename = gk_strdup(argv[gk_optind++]);362params->nparts = atoi(argv[gk_optind++]);363364if (params->nparts < 2)365errexit("The number of partitions should be greater than 1!\n");366367368/* Set the ptype-specific defaults */369if (params->ptype == METIS_PTYPE_RB) {370params->rtype = METIS_RTYPE_FM;371}372if (params->ptype == METIS_PTYPE_KWAY) {373params->iptype = METIS_IPTYPE_METISRB;374params->rtype = METIS_RTYPE_GREEDY;375}376377/* Check for invalid parameter combination */378if (params->ptype == METIS_PTYPE_RB) {379if (params->contig)380errexit("***The -contig option cannot be specified with rb partitioning. Will be ignored.\n");381if (params->minconn)382errexit("***The -minconn option cannot be specified with rb partitioning. Will be ignored. \n");383if (params->objtype == METIS_OBJTYPE_VOL)384errexit("The -objtype=vol option cannot be specified with rb partitioning.\n");385}386387return params;388}389390391392393