Path: blob/devel/elmergrid/src/metis-5.1.0/programs/cmdline_ndmetis.c
3206 views
/*!1\file cmdline_ndmetis.c2\brief Command-line argument parsing for ndmetis34\date 12/24/20085\author George6\version\verbatim $Id: cmdline_ndmetis.c 13900 2013-03-24 15:27:07Z karypis $\endverbatim7*/89#include "metisbin.h"101112/*-------------------------------------------------------------------13* Command-line options14*-------------------------------------------------------------------*/15static struct gk_option long_options[] = {16{"ctype", 1, 0, METIS_OPTION_CTYPE},17{"iptype", 1, 0, METIS_OPTION_IPTYPE},18{"rtype", 1, 0, METIS_OPTION_RTYPE},19{"ufactor", 1, 0, METIS_OPTION_UFACTOR},20{"pfactor", 1, 0, METIS_OPTION_PFACTOR},21{"nocompress", 0, 0, METIS_OPTION_COMPRESS},22{"ccorder", 0, 0, METIS_OPTION_CCORDER},23{"no2hop", 0, 0, METIS_OPTION_NO2HOP},24{"nooutput", 0, 0, METIS_OPTION_NOOUTPUT},25{"niter", 1, 0, METIS_OPTION_NITER},26{"nseps", 1, 0, METIS_OPTION_NSEPS},27{"seed", 1, 0, METIS_OPTION_SEED},28{"dbglvl", 1, 0, METIS_OPTION_DBGLVL},29{"help", 0, 0, METIS_OPTION_HELP},30{0, 0, 0, 0}31};323334static gk_StringMap_t ctype_options[] = {35{"rm", METIS_CTYPE_RM},36{"shem", METIS_CTYPE_SHEM},37{NULL, 0}38};3940static gk_StringMap_t iptype_options[] = {41{"edge", METIS_IPTYPE_EDGE},42{"node", METIS_IPTYPE_NODE},43{NULL, 0}44};4546static gk_StringMap_t rtype_options[] = {47{"2sided", METIS_RTYPE_SEP2SIDED},48{"1sided", METIS_RTYPE_SEP1SIDED},49{NULL, 0}50};51525354/*-------------------------------------------------------------------55* Mini help56*-------------------------------------------------------------------*/57static char helpstr[][100] =58{59" ",60"Usage: ndmetis [options] <filename>",61" ",62" Required parameters",63" filename Stores the graph to be partitioned.",64" ",65" Optional parameters",66" -ctype=string",67" Specifies the scheme to be used to match the vertices of the graph",68" during the coarsening.",69" The possible values are:",70" rm - Random matching",71" shem - Sorted heavy-edge matching [default]",72" ",73" -iptype=string [applies only when -ptype=rb]",74" Specifies the scheme to be used to compute the initial bisection",75" of the graph.",76" The possible values are:",77" edge - Separator from an edge cut",78" node - Separator from a greedy node-based strategy [default]",79" ",80" -rtype=string",81" Specifies the scheme to be used for refinement.",82" The possible values are:",83" 1sided - 1-sided node-based refinement [default]",84" 2sided - 2-sided node-based refinement",85" ",86" -ufactor=int",87" Specifies the maximum allowed load imbalance between the left and",88" right partitions during each bisection. The load imbalanced is",89" measured as the ratio of the 2*max(left,right)/(left+right), where",90" left and right are the sizes of the respective partitions. ",91" A value of x indicates that the allowed load imbalance is 1+x/1000.",92" Default is 200, indicating a load imbalance of 1.20.",93" ",94" -pfactor=int",95" Specifies the minimum degree of the vertices that will be ordered ",96" last. If the specified value is x>0, then any vertices with a degree",97" greater than 0.1*x*(average degree) are removed from the graph, an",98" ordering of the rest of the vertices is computed, and an overall ",99" ordering is computed by ordering the removed vertices at the end ",100" of the overall ordering.",101" Default value is 0, indicating that no vertices are removed",102" ",103" -no2hop",104" Specifies that the coarsening will not perform any 2-hop matchings",105" when the standard matching fails to sufficiently contract the graph.",106" ",107" -nocompress",108" Specifies that the graph should not be compressed by combining",109" together vertices that have identical adjacency lists.",110" ",111" -ccorder",112" Specifies if the connected components of the graph should first be ",113" identified and ordered separately.",114" ",115" -niter=int",116" Specifies the maximum number of iterations for the refinement ",117" algorithms at each stage of the uncoarsening process. Default is 10.",118" ",119" -nseps=int",120" Specifies the number of different separators that it will compute at",121" each level of the nested dissection. The final separator that is used",122" is the smallest one. Default is 1.",123" ",124" -nooutput",125" Specifies that no ordering file should be generated.",126" ",127" -seed=int",128" Selects the seed of the random number generator. ",129" ",130" -dbglvl=int ",131" Selects the dbglvl. ",132" ",133" -help",134" Prints this message.",135""136};137138static char shorthelpstr[][100] = {139" ",140" Usage: ndmetis [options] <filename>",141" use 'ndmetis -help' for a summary of the options.",142""143};144145146147/*************************************************************************/148/*! This is the entry point of the command-line argument parser */149/*************************************************************************/150params_t *parse_cmdline(int argc, char *argv[])151{152int i, j, k;153int c, option_index;154params_t *params;155156params = (params_t *)gk_malloc(sizeof(params_t), "parse_cmdline");157memset((void *)params, 0, sizeof(params_t));158159/* initialize the params data structure */160params->ctype = METIS_CTYPE_SHEM;161params->iptype = METIS_IPTYPE_NODE;162params->rtype = METIS_RTYPE_SEP1SIDED;163164params->ufactor = OMETIS_DEFAULT_UFACTOR;165params->pfactor = 0;166params->compress = 1;167params->ccorder = 0;168params->no2hop = 0;169170params->nooutput = 0;171params->wgtflag = 1;172173params->nseps = 1;174params->niter = 10;175176params->seed = -1;177params->dbglvl = 0;178179params->filename = NULL;180params->nparts = 1;181182183gk_clearcputimer(params->iotimer);184gk_clearcputimer(params->parttimer);185gk_clearcputimer(params->reporttimer);186187188/* Parse the command line arguments */189while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) {190switch (c) {191case METIS_OPTION_CTYPE:192if (gk_optarg)193if ((params->ctype = gk_GetStringID(ctype_options, gk_optarg)) == -1)194errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);195break;196case METIS_OPTION_IPTYPE:197if (gk_optarg)198if ((params->iptype = gk_GetStringID(iptype_options, gk_optarg)) == -1)199errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);200break;201202case METIS_OPTION_RTYPE:203if (gk_optarg)204if ((params->rtype = gk_GetStringID(rtype_options, gk_optarg)) == -1)205errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);206break;207208case METIS_OPTION_UFACTOR:209if (gk_optarg) params->ufactor = (idx_t)atoi(gk_optarg);210break;211212case METIS_OPTION_PFACTOR:213if (gk_optarg) params->pfactor = (idx_t)atoi(gk_optarg);214break;215216case METIS_OPTION_COMPRESS:217params->compress = 0;218break;219220case METIS_OPTION_CCORDER:221params->ccorder = 1;222break;223224case METIS_OPTION_NO2HOP:225params->no2hop = 1;226break;227228case METIS_OPTION_NOOUTPUT:229params->nooutput = 1;230break;231232case METIS_OPTION_NSEPS:233if (gk_optarg) params->nseps = (idx_t)atoi(gk_optarg);234break;235case METIS_OPTION_NITER:236if (gk_optarg) params->niter = (idx_t)atoi(gk_optarg);237break;238239case METIS_OPTION_SEED:240if (gk_optarg) params->seed = (idx_t)atoi(gk_optarg);241break;242243case METIS_OPTION_DBGLVL:244if (gk_optarg) params->dbglvl = (idx_t)atoi(gk_optarg);245break;246247case METIS_OPTION_HELP:248for (i=0; strlen(helpstr[i]) > 0; i++)249printf("%s\n", helpstr[i]);250exit(0);251break;252case '?':253default:254errexit("Illegal command-line option(s)\n"255"Use %s -help for a summary of the options.\n", argv[0]);256}257}258259if (argc-gk_optind != 1) {260printf("Missing parameters.");261for (i=0; strlen(shorthelpstr[i]) > 0; i++)262printf("%s\n", shorthelpstr[i]);263exit(0);264}265266params->filename = gk_strdup(argv[gk_optind++]);267268return params;269}270271272273274