Path: blob/devel/elmergrid/src/metis-5.1.0/programs/cmdline_mpmetis.c
3206 views
/*!1\file cmdline_mpmetis.c23\brief Command-line argument parsing for mpmetis45\date 12/24/20086\author George7\version\verbatim $Id: cmdline_mpmetis.c 13905 2013-03-25 13:21:20Z karypis $\endverbatim8*/910#include "metisbin.h"111213/*-------------------------------------------------------------------14* Command-line options15*-------------------------------------------------------------------*/16static struct gk_option long_options[] = {17{"gtype", 1, 0, METIS_OPTION_GTYPE},18{"ptype", 1, 0, METIS_OPTION_PTYPE},19{"objtype", 1, 0, METIS_OPTION_OBJTYPE},2021{"ctype", 1, 0, METIS_OPTION_CTYPE},22{"iptype", 1, 0, METIS_OPTION_IPTYPE},2324{"minconn", 0, 0, METIS_OPTION_MINCONN},25{"contig", 0, 0, METIS_OPTION_CONTIG},2627{"nooutput", 0, 0, METIS_OPTION_NOOUTPUT},2829{"ufactor", 1, 0, METIS_OPTION_UFACTOR},30{"niter", 1, 0, METIS_OPTION_NITER},31{"ncuts", 1, 0, METIS_OPTION_NCUTS},32{"ncommon", 1, 0, METIS_OPTION_NCOMMON},3334{"tpwgts", 1, 0, METIS_OPTION_TPWGTS},3536{"seed", 1, 0, METIS_OPTION_SEED},3738{"dbglvl", 1, 0, METIS_OPTION_DBGLVL},3940{"help", 0, 0, METIS_OPTION_HELP},41{0, 0, 0, 0}42};43444546/*-------------------------------------------------------------------47* Mappings for the various parameter values48*-------------------------------------------------------------------*/49static gk_StringMap_t gtype_options[] = {50{"dual", METIS_GTYPE_DUAL},51{"nodal", METIS_GTYPE_NODAL},52{NULL, 0}53};5455static gk_StringMap_t ptype_options[] = {56{"rb", METIS_PTYPE_RB},57{"kway", METIS_PTYPE_KWAY},58{NULL, 0}59};6061static gk_StringMap_t objtype_options[] = {62{"cut", METIS_OBJTYPE_CUT},63{"vol", METIS_OBJTYPE_VOL},64{NULL, 0}65};6667static gk_StringMap_t ctype_options[] = {68{"rm", METIS_CTYPE_RM},69{"shem", METIS_CTYPE_SHEM},70{NULL, 0}71};7273static gk_StringMap_t iptype_options[] = {74{"grow", METIS_IPTYPE_GROW},75{"random", METIS_IPTYPE_RANDOM},76{NULL, 0}77};787980/*-------------------------------------------------------------------81* Mini help82*-------------------------------------------------------------------*/83static char helpstr[][100] =84{85" ",86"Usage: mpmetis [options] meshfile nparts",87" ",88" Required parameters",89" meshfile Stores the mesh to be partitioned.",90" nparts The number of partitions to split the mesh.",91" ",92" Optional parameters",93" -gtype=string",94" Specifies the graph to be used for computing the partitioning",95" The possible values are:",96" dual - Partition the dual graph of the mesh [default]",97" nodal - Partition the nodal graph of the mesh",98" ",99" -ptype=string",100" Specifies the scheme to be used for computing the k-way partitioning.",101" The possible values are:",102" rb - Recursive bisectioning",103" kway - Direct k-way partitioning [default]",104" ",105" -ctype=string",106" Specifies the scheme to be used to match the vertices of the graph",107" during the coarsening.",108" The possible values are:",109" rm - Random matching",110" shem - Sorted heavy-edge matching [default]",111" ",112" -iptype=string [applies only when -ptype=rb]",113" Specifies the scheme to be used to compute the initial partitioning",114" of the graph.",115" The possible values are:",116" grow - Grow a bisection using a greedy strategy [default]",117" random - Compute a bisection at random",118" ",119" -objtype=string [applies only when -ptype=kway]",120" Specifies the objective that the partitioning routines will optimize.",121" The possible values are:",122" cut - Minimize the edgecut [default]",123" vol - Minimize the total communication volume",124" ",125" -contig [applies only when -ptype=kway]",126" Specifies that the partitioning routines should try to produce",127" partitions that are contiguous. Note that if the input graph is not",128" connected this option is ignored.",129" ",130" -minconn [applies only when -ptype=kway]",131" Specifies that the partitioning routines should try to minimize the",132" maximum degree of the subdomain graph, i.e., the graph in which each",133" partition is a node, and edges connect subdomains with a shared",134" interface.",135" ",136" -tpwgts=filename",137" Specifies the name of the file that stores the target weights for",138" each partition. By default, all partitions are assumed to be of ",139" the same size.",140" ",141" -ufactor=int",142" Specifies the maximum allowed load imbalance among the partitions.",143" A value of x indicates that the allowed load imbalance is 1+x/1000.",144" For ptype=rb, the load imbalance is measured as the ratio of the ",145" 2*max(left,right)/(left+right), where left and right are the sizes",146" of the respective partitions at each bisection. ",147" For ptype=kway, the load imbalance is measured as the ratio of ",148" max_i(pwgts[i])/avgpwgt, where pwgts[i] is the weight of the ith",149" partition and avgpwgt is the sum of the total vertex weights divided",150" by the number of partitions requested.",151" For ptype=rb, the default value is 1 (i.e., load imbalance of 1.001).",152" For ptype=kway, the default value is 30 (i.e., load imbalance of 1.03).",153" ",154" -ncommon=int",155" Specifies the common number of nodes that two elements must have",156" in order to put an edge between them in the dual graph. Default is 1.",157" ",158" -niter=int",159" Specifies the number of iterations for the refinement algorithms",160" at each stage of the uncoarsening process. Default is 10.",161" ",162" -ncuts=int",163" Specifies the number of different partitionings that it will compute.",164" The final partitioning is the one that achieves the best edgecut or",165" communication volume. Default is 1.",166" ",167" -nooutput",168" Specifies that no partitioning file should be generated.",169" ",170" -seed=int",171" Selects the seed of the random number generator. ",172" ",173" -dbglvl=int ",174" Selects the dbglvl. ",175" ",176" -help",177" Prints this message.",178""179};180181static char shorthelpstr[][100] = {182" ",183" Usage: mpmetis [options] <filename> <nparts>",184" use 'mpmetis -help' for a summary of the options.",185""186};187188189190/*************************************************************************191* This is the entry point of the command-line argument parser192**************************************************************************/193params_t *parse_cmdline(int argc, char *argv[])194{195int i, j, k;196int c, option_index;197params_t *params;198199params = (params_t *)gk_malloc(sizeof(params_t), "parse_cmdline");200memset((void *)params, 0, sizeof(params_t));201202/* initialize the params data structure */203params->gtype = METIS_GTYPE_DUAL;204params->ptype = METIS_PTYPE_KWAY;205params->objtype = METIS_OBJTYPE_CUT;206params->ctype = METIS_CTYPE_SHEM;207params->iptype = METIS_IPTYPE_GROW;208params->rtype = -1;209210params->minconn = 0;211params->contig = 0;212213params->nooutput = 0;214params->wgtflag = 3;215216params->ncuts = 1;217params->niter = 10;218params->ncommon = 1;219220params->dbglvl = 0;221params->balance = 0;222params->seed = -1;223params->dbglvl = 0;224225params->tpwgtsfile = NULL;226227params->filename = NULL;228params->nparts = 1;229230params->ufactor = -1;231232gk_clearcputimer(params->iotimer);233gk_clearcputimer(params->parttimer);234gk_clearcputimer(params->reporttimer);235236237/* Parse the command line arguments */238while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) {239switch (c) {240case METIS_OPTION_GTYPE:241if (gk_optarg)242if ((params->gtype = gk_GetStringID(gtype_options, gk_optarg)) == -1)243errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);244break;245case METIS_OPTION_PTYPE:246if (gk_optarg)247if ((params->ptype = gk_GetStringID(ptype_options, gk_optarg)) == -1)248errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);249break;250case METIS_OPTION_OBJTYPE:251if (gk_optarg)252if ((params->objtype = gk_GetStringID(objtype_options, gk_optarg)) == -1)253errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);254break;255case METIS_OPTION_CTYPE:256if (gk_optarg)257if ((params->ctype = gk_GetStringID(ctype_options, gk_optarg)) == -1)258errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);259break;260case METIS_OPTION_IPTYPE:261if (gk_optarg)262if ((params->iptype = gk_GetStringID(iptype_options, gk_optarg)) == -1)263errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);264break;265266/*267case METIS_OPTION_RTYPE:268if (gk_optarg)269if ((params->rtype = gk_GetStringID(rtype_options, gk_optarg)) == -1)270errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);271break;272*/273274case METIS_OPTION_CONTIG:275params->contig = 1;276break;277278case METIS_OPTION_MINCONN:279params->minconn = 1;280break;281282case METIS_OPTION_NOOUTPUT:283params->nooutput = 1;284break;285286case METIS_OPTION_BALANCE:287params->balance = 1;288break;289290case METIS_OPTION_TPWGTS:291if (gk_optarg) params->tpwgtsfile = gk_strdup(gk_optarg);292break;293294case METIS_OPTION_NCUTS:295if (gk_optarg) params->ncuts = (idx_t)atoi(gk_optarg);296break;297case METIS_OPTION_NITER:298if (gk_optarg) params->niter = (idx_t)atoi(gk_optarg);299break;300301case METIS_OPTION_NCOMMON:302if (gk_optarg) params->ncommon = (idx_t)atoi(gk_optarg);303break;304305case METIS_OPTION_UFACTOR:306if (gk_optarg) params->ufactor = (idx_t)atoi(gk_optarg);307break;308309case METIS_OPTION_SEED:310if (gk_optarg) params->seed = (idx_t)atoi(gk_optarg);311break;312313case METIS_OPTION_DBGLVL:314if (gk_optarg) params->dbglvl = (idx_t)atoi(gk_optarg);315break;316317case METIS_OPTION_HELP:318for (i=0; strlen(helpstr[i]) > 0; i++)319printf("%s\n", helpstr[i]);320exit(0);321break;322case '?':323default:324errexit("Illegal command-line option(s)\n"325"Use %s -help for a summary of the options.\n", argv[0]);326}327}328329if (argc-gk_optind != 2) {330printf("Missing parameters.");331for (i=0; strlen(shorthelpstr[i]) > 0; i++)332printf("%s\n", shorthelpstr[i]);333exit(0);334}335336params->filename = gk_strdup(argv[gk_optind++]);337params->nparts = atoi(argv[gk_optind++]);338339if (params->nparts < 2)340errexit("The number of partitions should be greater than 1!\n");341342343/* Set the ptype-specific defaults */344if (params->ptype == METIS_PTYPE_RB) {345params->rtype = METIS_RTYPE_FM;346}347if (params->ptype == METIS_PTYPE_KWAY) {348params->iptype = METIS_IPTYPE_METISRB;349params->rtype = METIS_RTYPE_GREEDY;350}351352/* Check for invalid parameter combination */353if (params->ptype == METIS_PTYPE_RB) {354if (params->contig)355errexit("The -contig option cannot be specified with rb partitioning.\n");356if (params->minconn)357errexit("The -minconn option cannot be specified with rb partitioning.\n");358if (params->objtype == METIS_OBJTYPE_VOL)359errexit("The -objtype=vol option cannot be specified with rb partitioning.\n");360}361362return params;363}364365366367368