00001
00010 #include "metisbin.h"
00011
00012
00013
00014
00015
00016 static struct gk_option long_options[] = {
00017 {"ctype", 1, 0, METIS_OPTION_CTYPE},
00018 {"iptype", 1, 0, METIS_OPTION_IPTYPE},
00019 {"rtype", 1, 0, METIS_OPTION_RTYPE},
00020 {"ufactor", 1, 0, METIS_OPTION_UFACTOR},
00021 {"pfactor", 1, 0, METIS_OPTION_PFACTOR},
00022 {"nocompress", 0, 0, METIS_OPTION_COMPRESS},
00023 {"ccorder", 0, 0, METIS_OPTION_CCORDER},
00024 {"no2hop", 0, 0, METIS_OPTION_NO2HOP},
00025 {"nooutput", 0, 0, METIS_OPTION_NOOUTPUT},
00026 {"niter", 1, 0, METIS_OPTION_NITER},
00027 {"nseps", 1, 0, METIS_OPTION_NSEPS},
00028 {"seed", 1, 0, METIS_OPTION_SEED},
00029 {"dbglvl", 1, 0, METIS_OPTION_DBGLVL},
00030 {"help", 0, 0, METIS_OPTION_HELP},
00031 {0, 0, 0, 0}
00032 };
00033
00034
00035 static gk_StringMap_t ctype_options[] = {
00036 {"rm", METIS_CTYPE_RM},
00037 {"shem", METIS_CTYPE_SHEM},
00038 {NULL, 0}
00039 };
00040
00041 static gk_StringMap_t iptype_options[] = {
00042 {"edge", METIS_IPTYPE_EDGE},
00043 {"node", METIS_IPTYPE_NODE},
00044 {NULL, 0}
00045 };
00046
00047 static gk_StringMap_t rtype_options[] = {
00048 {"2sided", METIS_RTYPE_SEP2SIDED},
00049 {"1sided", METIS_RTYPE_SEP1SIDED},
00050 {NULL, 0}
00051 };
00052
00053
00054
00055
00056
00057
00058 static char helpstr[][100] =
00059 {
00060 " ",
00061 "Usage: ndmetis [options] <filename>",
00062 " ",
00063 " Required parameters",
00064 " filename Stores the graph to be partitioned.",
00065 " ",
00066 " Optional parameters",
00067 " -ctype=string",
00068 " Specifies the scheme to be used to match the vertices of the graph",
00069 " during the coarsening.",
00070 " The possible values are:",
00071 " rm - Random matching",
00072 " shem - Sorted heavy-edge matching [default]",
00073 " ",
00074 " -iptype=string [applies only when -ptype=rb]",
00075 " Specifies the scheme to be used to compute the initial bisection",
00076 " of the graph.",
00077 " The possible values are:",
00078 " edge - Separator from an edge cut",
00079 " node - Separator from a greedy node-based strategy [default]",
00080 " ",
00081 " -rtype=string",
00082 " Specifies the scheme to be used for refinement.",
00083 " The possible values are:",
00084 " 1sided - 1-sided node-based refinement [default]",
00085 " 2sided - 2-sided node-based refinement",
00086 " ",
00087 " -ufactor=int",
00088 " Specifies the maximum allowed load imbalance between the left and",
00089 " right partitions during each bisection. The load imbalanced is",
00090 " measured as the ratio of the 2*max(left,right)/(left+right), where",
00091 " left and right are the sizes of the respective partitions. ",
00092 " A value of x indicates that the allowed load imbalance is 1+x/1000.",
00093 " Default is 200, indicating a load imbalance of 1.20.",
00094 " ",
00095 " -pfactor=int",
00096 " Specifies the minimum degree of the vertices that will be ordered ",
00097 " last. If the specified value is x>0, then any vertices with a degree",
00098 " greater than 0.1*x*(average degree) are removed from the graph, an",
00099 " ordering of the rest of the vertices is computed, and an overall ",
00100 " ordering is computed by ordering the removed vertices at the end ",
00101 " of the overall ordering.",
00102 " Default value is 0, indicating that no vertices are removed",
00103 " ",
00104 " -no2hop",
00105 " Specifies that the coarsening will not perform any 2-hop matchings",
00106 " when the standard matching fails to sufficiently contract the graph.",
00107 " ",
00108 " -nocompress",
00109 " Specifies that the graph should not be compressed by combining",
00110 " together vertices that have identical adjacency lists.",
00111 " ",
00112 " -ccorder",
00113 " Specifies if the connected components of the graph should first be ",
00114 " identified and ordered separately.",
00115 " ",
00116 " -niter=int",
00117 " Specifies the maximum number of iterations for the refinement ",
00118 " algorithms at each stage of the uncoarsening process. Default is 10.",
00119 " ",
00120 " -nseps=int",
00121 " Specifies the number of different separators that it will compute at",
00122 " each level of the nested dissection. The final separator that is used",
00123 " is the smallest one. Default is 1.",
00124 " ",
00125 " -nooutput",
00126 " Specifies that no ordering file should be generated.",
00127 " ",
00128 " -seed=int",
00129 " Selects the seed of the random number generator. ",
00130 " ",
00131 " -dbglvl=int ",
00132 " Selects the dbglvl. ",
00133 " ",
00134 " -help",
00135 " Prints this message.",
00136 ""
00137 };
00138
00139 static char shorthelpstr[][100] = {
00140 " ",
00141 " Usage: ndmetis [options] <filename>",
00142 " use 'ndmetis -help' for a summary of the options.",
00143 ""
00144 };
00145
00146
00147
00148
00150
00151 params_t *parse_cmdline(int argc, char *argv[])
00152 {
00153 int i, j, k;
00154 int c, option_index;
00155 params_t *params;
00156
00157 params = (params_t *)gk_malloc(sizeof(params_t), "parse_cmdline");
00158 memset((void *)params, 0, sizeof(params_t));
00159
00160
00161 params->ctype = METIS_CTYPE_SHEM;
00162 params->iptype = METIS_IPTYPE_NODE;
00163 params->rtype = METIS_RTYPE_SEP1SIDED;
00164
00165 params->ufactor = OMETIS_DEFAULT_UFACTOR;
00166 params->pfactor = 0;
00167 params->compress = 1;
00168 params->ccorder = 0;
00169 params->no2hop = 0;
00170
00171 params->nooutput = 0;
00172 params->wgtflag = 1;
00173
00174 params->nseps = 1;
00175 params->niter = 10;
00176
00177 params->seed = -1;
00178 params->dbglvl = 0;
00179
00180 params->filename = NULL;
00181 params->nparts = 1;
00182
00183
00184 gk_clearcputimer(params->iotimer);
00185 gk_clearcputimer(params->parttimer);
00186 gk_clearcputimer(params->reporttimer);
00187
00188
00189
00190 while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) {
00191 switch (c) {
00192 case METIS_OPTION_CTYPE:
00193 if (gk_optarg)
00194 if ((params->ctype = gk_GetStringID(ctype_options, gk_optarg)) == -1)
00195 errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);
00196 break;
00197 case METIS_OPTION_IPTYPE:
00198 if (gk_optarg)
00199 if ((params->iptype = gk_GetStringID(iptype_options, gk_optarg)) == -1)
00200 errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);
00201 break;
00202
00203 case METIS_OPTION_RTYPE:
00204 if (gk_optarg)
00205 if ((params->rtype = gk_GetStringID(rtype_options, gk_optarg)) == -1)
00206 errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg);
00207 break;
00208
00209 case METIS_OPTION_UFACTOR:
00210 if (gk_optarg) params->ufactor = (idx_t)atoi(gk_optarg);
00211 break;
00212
00213 case METIS_OPTION_PFACTOR:
00214 if (gk_optarg) params->pfactor = (idx_t)atoi(gk_optarg);
00215 break;
00216
00217 case METIS_OPTION_COMPRESS:
00218 params->compress = 0;
00219 break;
00220
00221 case METIS_OPTION_CCORDER:
00222 params->ccorder = 1;
00223 break;
00224
00225 case METIS_OPTION_NO2HOP:
00226 params->no2hop = 1;
00227 break;
00228
00229 case METIS_OPTION_NOOUTPUT:
00230 params->nooutput = 1;
00231 break;
00232
00233 case METIS_OPTION_NSEPS:
00234 if (gk_optarg) params->nseps = (idx_t)atoi(gk_optarg);
00235 break;
00236 case METIS_OPTION_NITER:
00237 if (gk_optarg) params->niter = (idx_t)atoi(gk_optarg);
00238 break;
00239
00240 case METIS_OPTION_SEED:
00241 if (gk_optarg) params->seed = (idx_t)atoi(gk_optarg);
00242 break;
00243
00244 case METIS_OPTION_DBGLVL:
00245 if (gk_optarg) params->dbglvl = (idx_t)atoi(gk_optarg);
00246 break;
00247
00248 case METIS_OPTION_HELP:
00249 for (i=0; strlen(helpstr[i]) > 0; i++)
00250 printf("%s\n", helpstr[i]);
00251 exit(0);
00252 break;
00253 case '?':
00254 default:
00255 errexit("Illegal command-line option(s)\n"
00256 "Use %s -help for a summary of the options.\n", argv[0]);
00257 }
00258 }
00259
00260 if (argc-gk_optind != 1) {
00261 printf("Missing parameters.");
00262 for (i=0; strlen(shorthelpstr[i]) > 0; i++)
00263 printf("%s\n", shorthelpstr[i]);
00264 exit(0);
00265 }
00266
00267 params->filename = gk_strdup(argv[gk_optind++]);
00268
00269 return params;
00270 }
00271
00272