1 /*!
2 \file cmdline_ndmetis.c
3 \brief Command-line argument parsing for ndmetis
4 
5 \date 12/24/2008
6 \author George
7 \version\verbatim $Id: cmdline_ndmetis.c 13900 2013-03-24 15:27:07Z karypis $\endverbatim
8 */
9 
10 #include "metisbin.h"
11 
12 
13 /*-------------------------------------------------------------------
14  * Command-line options
15  *-------------------------------------------------------------------*/
16 static struct gk_option long_options[] = {
17   {"ctype",          1,      0,      METIS_OPTION_CTYPE},
18   {"iptype",         1,      0,      METIS_OPTION_IPTYPE},
19   {"rtype",          1,      0,      METIS_OPTION_RTYPE},
20   {"ufactor",        1,      0,      METIS_OPTION_UFACTOR},
21   {"pfactor",        1,      0,      METIS_OPTION_PFACTOR},
22   {"nocompress",     0,      0,      METIS_OPTION_COMPRESS},
23   {"ccorder",        0,      0,      METIS_OPTION_CCORDER},
24   {"no2hop",         0,      0,      METIS_OPTION_NO2HOP},
25   {"nooutput",       0,      0,      METIS_OPTION_NOOUTPUT},
26   {"niter",          1,      0,      METIS_OPTION_NITER},
27   {"nseps",          1,      0,      METIS_OPTION_NSEPS},
28   {"seed",           1,      0,      METIS_OPTION_SEED},
29   {"dbglvl",         1,      0,      METIS_OPTION_DBGLVL},
30   {"help",           0,      0,      METIS_OPTION_HELP},
31   {0,                0,      0,      0}
32 };
33 
34 
35 static gk_StringMap_t ctype_options[] = {
36  {"rm",                 METIS_CTYPE_RM},
37  {"shem",               METIS_CTYPE_SHEM},
38  {NULL,                 0}
39 };
40 
41 static gk_StringMap_t iptype_options[] = {
42  {"edge",               METIS_IPTYPE_EDGE},
43  {"node",               METIS_IPTYPE_NODE},
44  {NULL,                 0}
45 };
46 
47 static gk_StringMap_t rtype_options[] = {
48  {"2sided",             METIS_RTYPE_SEP2SIDED},
49  {"1sided",             METIS_RTYPE_SEP1SIDED},
50  {NULL,                 0}
51 };
52 
53 
54 
55 /*-------------------------------------------------------------------
56  * Mini help
57  *-------------------------------------------------------------------*/
58 static char helpstr[][100] =
59 {
60 " ",
61 "Usage: ndmetis [options] <filename>",
62 " ",
63 " Required parameters",
64 "    filename    Stores the graph to be partitioned.",
65 " ",
66 " Optional parameters",
67 "  -ctype=string",
68 "     Specifies the scheme to be used to match the vertices of the graph",
69 "     during the coarsening.",
70 "     The possible values are:",
71 "        rm       - Random matching",
72 "        shem     - Sorted heavy-edge matching [default]",
73 " ",
74 "  -iptype=string [applies only when -ptype=rb]",
75 "     Specifies the scheme to be used to compute the initial bisection",
76 "     of the graph.",
77 "     The possible values are:",
78 "        edge     - Separator from an edge cut",
79 "        node     - Separator from a greedy node-based strategy [default]",
80 " ",
81 "  -rtype=string",
82 "     Specifies the scheme to be used for refinement.",
83 "     The possible values are:",
84 "        1sided   - 1-sided node-based refinement [default]",
85 "        2sided   - 2-sided node-based refinement",
86 " ",
87 "  -ufactor=int",
88 "     Specifies the maximum allowed load imbalance between the left and",
89 "     right partitions during each bisection. The load imbalanced is",
90 "     measured as the ratio of the 2*max(left,right)/(left+right), where",
91 "     left and right are the sizes of the respective partitions. ",
92 "     A value of x indicates that the allowed load imbalance is 1+x/1000.",
93 "     Default is 200, indicating a load imbalance of 1.20.",
94 " ",
95 "  -pfactor=int",
96 "     Specifies the minimum degree of the vertices that will be ordered ",
97 "     last. If the specified value is x>0, then any vertices with a degree",
98 "     greater than 0.1*x*(average degree) are removed from the graph, an",
99 "     ordering of the rest of the vertices is computed, and an overall ",
100 "     ordering is computed by ordering the removed vertices at the end ",
101 "     of the overall ordering.",
102 "     Default value is 0, indicating that no vertices are removed",
103 " ",
104 "  -no2hop",
105 "     Specifies that the coarsening will not perform any 2-hop matchings",
106 "     when the standard matching fails to sufficiently contract the graph.",
107 " ",
108 "  -nocompress",
109 "     Specifies that the graph should not be compressed by combining",
110 "     together vertices that have identical adjacency lists.",
111 " ",
112 "  -ccorder",
113 "     Specifies if the connected components of the graph should first be ",
114 "     identified and ordered separately.",
115 " ",
116 "  -niter=int",
117 "     Specifies the maximum number of iterations for the refinement ",
118 "     algorithms at each stage of the uncoarsening process. Default is 10.",
119 " ",
120 "  -nseps=int",
121 "     Specifies the number of different separators that it will compute at",
122 "     each level of the nested dissection. The final separator that is used",
123 "     is the smallest one. Default is 1.",
124 " ",
125 "  -nooutput",
126 "     Specifies that no ordering file should be generated.",
127 " ",
128 "  -seed=int",
129 "     Selects the seed of the random number generator.  ",
130 " ",
131 "  -dbglvl=int      ",
132 "     Selects the dbglvl.  ",
133 " ",
134 "  -help",
135 "     Prints this message.",
136 ""
137 };
138 
139 static char shorthelpstr[][100] = {
140 " ",
141 "   Usage: ndmetis [options] <filename>",
142 "          use 'ndmetis -help' for a summary of the options.",
143 ""
144 };
145 
146 
147 
148 /*************************************************************************/
149 /*! This is the entry point of the command-line argument parser */
150 /*************************************************************************/
parse_cmdline(int argc,char * argv[])151 params_t *parse_cmdline(int argc, char *argv[])
152 {
153   int i, j, k;
154   int c, option_index;
155   params_t *params;
156 
157   params = (params_t *)gk_malloc(sizeof(params_t), "parse_cmdline");
158   memset((void *)params, 0, sizeof(params_t));
159 
160   /* initialize the params data structure */
161   params->ctype         = METIS_CTYPE_SHEM;
162   params->iptype        = METIS_IPTYPE_NODE;
163   params->rtype         = METIS_RTYPE_SEP1SIDED;
164 
165   params->ufactor       = OMETIS_DEFAULT_UFACTOR;
166   params->pfactor       = 0;
167   params->compress      = 1;
168   params->ccorder       = 0;
169   params->no2hop        = 0;
170 
171   params->nooutput      = 0;
172   params->wgtflag       = 1;
173 
174   params->nseps         = 1;
175   params->niter         = 10;
176 
177   params->seed          = -1;
178   params->dbglvl        = 0;
179 
180   params->filename      = NULL;
181   params->nparts        = 1;
182 
183 
184   gk_clearcputimer(params->iotimer);
185   gk_clearcputimer(params->parttimer);
186   gk_clearcputimer(params->reporttimer);
187 
188 
189   /* Parse the command line arguments  */
190   while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) {
191     switch (c) {
192       case METIS_OPTION_CTYPE:
193         if (gk_optarg)
194           if ((params->ctype = gk_GetStringID(ctype_options, gk_optarg)) == -1)
195             errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);
196         break;
197       case METIS_OPTION_IPTYPE:
198         if (gk_optarg)
199           if ((params->iptype = gk_GetStringID(iptype_options, gk_optarg)) == -1)
200             errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);
201         break;
202 
203       case METIS_OPTION_RTYPE:
204         if (gk_optarg)
205           if ((params->rtype = gk_GetStringID(rtype_options, gk_optarg)) == -1)
206             errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);
207         break;
208 
209       case METIS_OPTION_UFACTOR:
210         if (gk_optarg) params->ufactor = (idx_t)atoi(gk_optarg);
211         break;
212 
213       case METIS_OPTION_PFACTOR:
214         if (gk_optarg) params->pfactor = (idx_t)atoi(gk_optarg);
215         break;
216 
217       case METIS_OPTION_COMPRESS:
218         params->compress = 0;
219         break;
220 
221       case METIS_OPTION_CCORDER:
222         params->ccorder = 1;
223         break;
224 
225       case METIS_OPTION_NO2HOP:
226         params->no2hop = 1;
227         break;
228 
229       case METIS_OPTION_NOOUTPUT:
230         params->nooutput = 1;
231         break;
232 
233       case METIS_OPTION_NSEPS:
234         if (gk_optarg) params->nseps = (idx_t)atoi(gk_optarg);
235         break;
236       case METIS_OPTION_NITER:
237         if (gk_optarg) params->niter = (idx_t)atoi(gk_optarg);
238         break;
239 
240       case METIS_OPTION_SEED:
241         if (gk_optarg) params->seed = (idx_t)atoi(gk_optarg);
242         break;
243 
244       case METIS_OPTION_DBGLVL:
245         if (gk_optarg) params->dbglvl = (idx_t)atoi(gk_optarg);
246         break;
247 
248       case METIS_OPTION_HELP:
249         for (i=0; strlen(helpstr[i]) > 0; i++)
250           printf("%s\n", helpstr[i]);
251         exit(0);
252         break;
253       case '?':
254       default:
255         errexit("Illegal command-line option(s)\n"
256                 "Use %s -help for a summary of the options.\n", argv[0]);
257     }
258   }
259 
260   if (argc-gk_optind != 1) {
261     printf("Missing parameters.");
262     for (i=0; strlen(shorthelpstr[i]) > 0; i++)
263       printf("%s\n", shorthelpstr[i]);
264     exit(0);
265   }
266 
267   params->filename = gk_strdup(argv[gk_optind++]);
268 
269   return params;
270 }
271 
272 
273