void cmdline_parse(params_t *params, int argc, char *argv[]) { gk_idx_t i, j, k; int type=0; int c, option_index; /* print the command line */ for (i=0; i<argc; i++) printf("%s ", argv[i]); printf("\n"); /* initialize the params data structure */ params->nnbrs = 100; params->minsim = 0.25; params->verbosity = -1; /* Parse the command line arguments */ while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) { switch (c) { case CMD_NNBRS: if (gk_optarg) { if ((params->nnbrs = atoi(gk_optarg)) < 1) errexit("The -nnbrs must be greater than 1.\n"); } break; case CMD_MINSIM: if (gk_optarg) { params->minsim = atof(gk_optarg); if (params->minsim < 0.0 ) errexit("The -minsim must be non-negative.\n"); } break; case CMD_VERBOSITY: if (gk_optarg) { params->verbosity = atoi(gk_optarg); if (params->verbosity < 0) errexit("The -verbosity must be non-negative.\n"); } break; case CMD_HELP: for (i=0; strlen(helpstr[i]) > 0; i++) printf("%s\n", helpstr[i]); exit(EXIT_SUCCESS); break; default: printf("Illegal command-line option(s)\nUse %s -help for a summary of the options.\n", argv[0]); exit(EXIT_FAILURE); } } /* Get the input/output file info */ if (argc-gk_optind == 0) { printf("Missing input/output file info.\n Use %s -help for a summary of the options.\n", argv[0]); exit(EXIT_FAILURE); } params->infstem = gk_strdup(argv[gk_optind++]); params->outfile = (gk_optind < argc ? gk_strdup(argv[gk_optind++]) : NULL); }
/************************************************************************* * This is the entry point of the command-line argument parser **************************************************************************/ params_t *parse_cmdline(int argc, char *argv[]) { int i, j, k; int c, option_index; params_t *params; params = (params_t *)gk_malloc(sizeof(params_t), "parse_cmdline"); memset((void *)params, 0, sizeof(params_t)); /* initialize the params data structure */ params->gtype = METIS_GTYPE_DUAL; params->ptype = METIS_PTYPE_KWAY; params->objtype = METIS_OBJTYPE_CUT; params->ctype = METIS_CTYPE_SHEM; params->iptype = METIS_IPTYPE_GROW; params->rtype = -1; params->minconn = 0; params->contig = 0; params->nooutput = 0; params->wgtflag = 3; params->ncuts = 1; params->niter = 10; params->ncommon = 1; params->dbglvl = 0; params->balance = 0; params->seed = -1; params->dbglvl = 0; params->tpwgtsfile = NULL; params->filename = NULL; params->nparts = 1; params->ufactor = -1; gk_clearcputimer(params->iotimer); gk_clearcputimer(params->parttimer); gk_clearcputimer(params->reporttimer); /* Parse the command line arguments */ while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) { switch (c) { case METIS_OPTION_GTYPE: if (gk_optarg) if ((params->gtype = gk_GetStringID(gtype_options, gk_optarg)) == -1) errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg); break; case METIS_OPTION_PTYPE: if (gk_optarg) if ((params->ptype = gk_GetStringID(ptype_options, gk_optarg)) == -1) errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg); break; case METIS_OPTION_OBJTYPE: if (gk_optarg) if ((params->objtype = gk_GetStringID(objtype_options, gk_optarg)) == -1) errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg); break; case METIS_OPTION_CTYPE: if (gk_optarg) if ((params->ctype = gk_GetStringID(ctype_options, gk_optarg)) == -1) errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg); break; case METIS_OPTION_IPTYPE: if (gk_optarg) if ((params->iptype = gk_GetStringID(iptype_options, gk_optarg)) == -1) errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg); break; /* case METIS_OPTION_RTYPE: if (gk_optarg) if ((params->rtype = gk_GetStringID(rtype_options, gk_optarg)) == -1) errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg); break; */ case METIS_OPTION_CONTIG: params->contig = 1; break; case METIS_OPTION_MINCONN: params->minconn = 1; break; case METIS_OPTION_NOOUTPUT: params->nooutput = 1; break; case METIS_OPTION_BALANCE: params->balance = 1; break; case METIS_OPTION_TPWGTS: if (gk_optarg) params->tpwgtsfile = gk_strdup(gk_optarg); break; case METIS_OPTION_NCUTS: if (gk_optarg) params->ncuts = (idx_t)atoi(gk_optarg); break; case METIS_OPTION_NITER: if (gk_optarg) params->niter = (idx_t)atoi(gk_optarg); break; case METIS_OPTION_NCOMMON: if (gk_optarg) params->ncommon = (idx_t)atoi(gk_optarg); break; case METIS_OPTION_UFACTOR: if (gk_optarg) params->ufactor = (idx_t)atoi(gk_optarg); break; case METIS_OPTION_SEED: if (gk_optarg) params->seed = (idx_t)atoi(gk_optarg); break; case METIS_OPTION_DBGLVL: if (gk_optarg) params->dbglvl = (idx_t)atoi(gk_optarg); break; case METIS_OPTION_HELP: for (i=0; strlen(helpstr[i]) > 0; i++) printf("%s\n", helpstr[i]); exit(0); break; case '?': default: errexit("Illegal command-line option(s)\n" "Use %s -help for a summary of the options.\n", argv[0]); } } if (argc-gk_optind != 2) { printf("Missing parameters."); for (i=0; strlen(shorthelpstr[i]) > 0; i++) printf("%s\n", shorthelpstr[i]); exit(0); } params->filename = gk_strdup(argv[gk_optind++]); params->nparts = atoi(argv[gk_optind++]); if (params->nparts < 2) errexit("The number of partitions should be greater than 1!\n"); /* Set the ptype-specific defaults */ if (params->ptype == METIS_PTYPE_RB) { params->rtype = METIS_RTYPE_FM; } if (params->ptype == METIS_PTYPE_KWAY) { params->iptype = METIS_IPTYPE_METISRB; params->rtype = METIS_RTYPE_GREEDY; } /* Check for invalid parameter combination */ if (params->ptype == METIS_PTYPE_RB) { if (params->contig) errexit("The -contig option cannot be specified with rb partitioning.\n"); if (params->minconn) errexit("The -minconn option cannot be specified with rb partitioning.\n"); if (params->objtype == METIS_OBJTYPE_VOL) errexit("The -objtype=vol option cannot be specified with rb partitioning.\n"); } return params; }
/************************************************************************* * This is the entry point of the command-line argument parser **************************************************************************/ void parse_cmdline(ParamType *params, int argc, char *argv[]) { int i, j, k; int c, option_index; /* initialize the params data structure */ params->mtype = PMETIS_CTYPE; params->itype = PMETIS_ITYPE; params->rtype = PMETIS_RTYPE; params->dbglvl = PMETIS_DBGLVL; params->balance = 0; params->seed = -1; params->dbglvl = 0; params->filename = NULL; params->nparts = 1; /* Parse the command line arguments */ while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) { switch (c) { case CMD_MTYPE: if (gk_optarg) if ((params->mtype = gk_GetStringID(mtype_options, gk_optarg)) == -1) errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg); break; case CMD_ITYPE: if (gk_optarg) if ((params->itype = gk_GetStringID(itype_options, gk_optarg)) == -1) errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg); break; case CMD_RTYPE: if (gk_optarg) if ((params->rtype = gk_GetStringID(rtype_options, gk_optarg)) == -1) errexit("Invalid option -%s=%s\n", long_options[option_index].name, gk_optarg); break; case CMD_BALANCE: params->balance = 1; break; case CMD_SEED: if (gk_optarg) params->seed = atoi(gk_optarg); break; case CMD_DBGLVL: if (gk_optarg) params->dbglvl = atoi(gk_optarg); break; case CMD_HELP: for (i=0; strlen(helpstr[i]) > 0; i++) mprintf("%s\n", helpstr[i]); exit(0); break; case '?': default: mprintf("Illegal command-line option(s)\nUse %s -help for a summary of the options.\n", argv[0]); exit(0); } } if (argc-gk_optind != 2) { mprintf("Missing parameters."); for (i=0; strlen(shorthelpstr[i]) > 0; i++) mprintf("%s\n", shorthelpstr[i]); exit(0); } params->filename = strdup(argv[gk_optind++]); params->nparts = atoi(argv[gk_optind++]); }
params_t *parse_cmdline(int argc, char *argv[]) { int i; int c, option_index; params_t *params; params = (params_t *)gk_malloc(sizeof(params_t), "parse_cmdline: params"); /* initialize the params data structure */ params->niter = 100; params->ppr = -1; params->ntvs = -1; params->eps = 1e-10; params->lamda = 0.80; params->infile = NULL; params->outfile = NULL; /* Parse the command line arguments */ while ((c = gk_getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) { switch (c) { case CMD_NITER: if (gk_optarg) params->niter = atoi(gk_optarg); break; case CMD_NTVS: if (gk_optarg) params->ntvs = atoi(gk_optarg); break; case CMD_PPR: if (gk_optarg) params->ppr = atoi(gk_optarg); break; case CMD_EPS: if (gk_optarg) params->eps = atof(gk_optarg); break; case CMD_LAMDA: if (gk_optarg) params->lamda = atof(gk_optarg); break; case CMD_HELP: for (i=0; strlen(helpstr[i]) > 0; i++) printf("%s\n", helpstr[i]); exit(0); break; case '?': default: printf("Illegal command-line option(s)\nUse %s -help for a summary of the options.\n", argv[0]); exit(0); } } if (argc-gk_optind != 2) { printf("Unrecognized parameters."); for (i=0; strlen(shorthelpstr[i]) > 0; i++) printf("%s\n", shorthelpstr[i]); exit(0); } params->infile = gk_strdup(argv[gk_optind++]); params->outfile = gk_strdup(argv[gk_optind++]); if (!gk_fexists(params->infile)) errexit("input file %s does not exist.\n", params->infile); if (params->ppr != -1 && params->ntvs != -1) errexit("Only one of the -ppr and -ntvs options can be specified.\n"); return params; }