Example #1
0
File: rbbdf.c Project: tttwwy/LMF
int main(int argc, char *argv[])
{
	idx_t options[METIS_NOPTIONS];
  	bigraph_t *bigraph;
  	idx_t *perm, *iperm;
  	params_t *params;
  	int status, i, j;

  	/* rdiags[i][0] and cdiags[i][0] saves the length of each array
  	 * excluding the first value */
  	idx_t **rdiags, **cdiags;
  	idx_t ndiags;

  	params = parse_cmdline(argc, argv);

  	gk_startcputimer(params->iotimer);
  	bigraph = ReadBiGraph(params);
  	gk_stopcputimer(params->iotimer);

  	if(bigraph == NULL){
  		printf("Input Error : nrows + ncols != nvtxs\n");
  		printf("\n***Metis returned with an error.\n");
  		return -1;
  	}

  	BDFPrintInfo(params, bigraph);

    METIS_SetDefaultOptions(options);
    /*User specific parameters*/
	options[METIS_OPTION_CTYPE]    = params->ctype;
	options[METIS_OPTION_IPTYPE]   = params->iptype;
	options[METIS_OPTION_RTYPE]    = params->rtype;
	options[METIS_OPTION_CCORDER]  = params->ccorder;
	options[METIS_OPTION_SEED]     = params->seed;
	options[METIS_OPTION_DBGLVL]   = params->dbglvl;
	options[METIS_OPTION_DENSITY] = params->density * DIVIDER;
	options[METIS_OPTION_NROWS] = params->nrows;
	options[METIS_OPTION_NCOLS] = params->ncols;
	options[METIS_OPTION_KAPPA] = params->kappa;
	options[METIS_OPTION_NDIAGS] = params->ndiags;

	/*Inner parameters*/
	options[METIS_OPTION_COMPRESS] = params->compress;
	options[METIS_OPTION_UFACTOR]  = params->ufactor;
	options[METIS_OPTION_PFACTOR]  = params->pfactor;
	options[METIS_OPTION_NCUTS] = params->ncuts;
	options[METIS_OPTION_NSEPS]    = params->nseps;
	options[METIS_OPTION_NITER]    = params->niter;
	options[METIS_OPTION_OBJTYPE] = params->objtype;

	perm  = imalloc(bigraph->super->nvtxs, "main: perm");
  	iperm = imalloc(bigraph->super->nvtxs, "main: iperm");

	gk_malloc_init();
	gk_startcputimer(params->parttimer);

	/* Initialize my global paramters */
	gk_clearcputimer(_parttimer);
	gk_clearcputimer(_nztimer);
	_totalcheck = 0;
	_firsthit = 0;
	_maxarea = -1;
	_maxnz = -1;
	_minarea = 700000000000;
	_minnz = 300000000;
	_avgarea = 0;
	_avgnz = 0;
	_maxdense = 0;
	_mindense = 0;

  	/* All the memory that is not allocated in this file should be allocated after
  	 * gk_malloc_init() and be freed before gk_GetCurMemoryUsed().
  	 * Memory that is allocated in this file should be free in the end of main()*/
  	status = METIS_NodeBDF(&bigraph->super->nvtxs, bigraph->super->xadj, bigraph->super->adjncy,
  			bigraph->super->vwgt, bigraph->nrows, bigraph->ncols,
  			options, bigraph->rlabel->label, bigraph->rlabel->ref, bigraph->clabel->label, bigraph->clabel->ref,
  			&rdiags, &cdiags, &ndiags, perm, iperm);

  	gk_stopcputimer(params->parttimer);

	if (gk_GetCurMemoryUsed() != 0)
    	printf("***It seems that Metis did not free all of its memory!\n");
	params->maxmemory = gk_GetMaxMemoryUsed();
	gk_malloc_cleanup(0);

	if (status != METIS_OK) {
		printf("\n***Metis returned with an error.\n");
	}
	else {
		if (! params->nooutput) {
	  		/* Write the permutation */
	  		gk_startcputimer(params->iotimer);
	  		WritePermutation(params->filename, iperm, bigraph->super->nvtxs);
	  		WriteDiags(params->filename, rdiags, cdiags, ndiags);
	  		gk_stopcputimer(params->iotimer);
		}
		BDFReportResults(params, bigraph);
	}

	/* free inner function memory */
	for (i = 0; i < ndiags; i++) {
		free((void*)rdiags[i]);
		free((void*)cdiags[i]);
	}
	free((void*)rdiags);
	free((void*)cdiags);

	/* free memroy allocated in this function */
	FreeBiGraph((ctrl_t*)NULL, &bigraph);
	gk_free((void **)&perm, &iperm, LTERM);
	gk_free((void **)&params->filename, &params->tpwgtsfile, &params->tpwgts,
	  &params->ubvec, &params, LTERM);

	return status;
}
Example #2
0
/*************************************************************************
* Let the game begin
**************************************************************************/
int main(int argc, char *argv[])
{
  idxtype i, j, ne, nn, etype, mtype, numflag=0, nparts, edgecut;
  idxtype *elmnts, *epart, *npart, *metype, *weights;
  double IOTmr, DUALTmr;
  char etypestr[5][5] = {"TRI", "TET", "HEX", "QUAD", "LINE"};
  GraphType graph;

  if (argc != 3) {
    mprintf("Usage: %s <meshfile> <nparts>\n",argv[0]);
    exit(0);
  }



  nparts = atoi(argv[2]);
  if (nparts < 2) {
    mprintf("nparts must be greater than one.\n");
    exit(0);
  }
   
  gk_clearcputimer(IOTmr);
  gk_clearcputimer(DUALTmr);
 
  mtype=MeshType(argv[1]);
  ne=MixedElements(argv[1]);
  metype = idxmalloc(ne, "main: metype");
  weights = idxmalloc(ne, "main: weights");

  gk_startcputimer(IOTmr);
 
  if(mtype==1)
       elmnts = ReadMesh(argv[1], &ne, &nn, &etype);
  else if(mtype==3)
       elmnts = ReadMeshWgt(argv[1], &ne, &nn, &etype, weights);
  else if(mtype==0)
       elmnts = ReadMixedMesh(argv[1], &ne, &nn, metype);
  else
       elmnts = ReadMixedMeshWgt(argv[1], &ne, &nn, metype, weights);

  gk_stopcputimer(IOTmr);

  epart = idxmalloc(ne, "main: epart");
  npart = idxmalloc(nn, "main: npart");

  mprintf("**********************************************************************\n");
  mprintf("%s", METISTITLE);
  mprintf("Mesh Information ----------------------------------------------------\n");
  if (mtype==1)
  mprintf("  Name: %s, #Elements: %D, #Nodes: %D, Etype: %s\n\n", argv[1], ne, nn, etypestr[etype-1]);
  else
  mprintf("  Name: %s, #Elements: %D, #Nodes: %D, Etype: %s\n\n", argv[1], ne, nn, "Mixed");
  mprintf("Partitioning Nodal Graph... -----------------------------------------\n");


  gk_startcputimer(DUALTmr);
  
  if (mtype==1 || mtype==3)
  METIS_PartMeshNodal(&ne, &nn, elmnts, &etype, &numflag, &nparts, &edgecut, epart, npart);
  else 
  METIS_PartMixedMeshNodal(&ne, &nn, elmnts, metype, &numflag, &nparts, &edgecut, epart, npart);
  
  gk_stopcputimer(DUALTmr);

  mprintf("  %D-way Edge-Cut: %7D, Balance: %5.2f\n", nparts, edgecut, ComputeElementBalance(ne, nparts, epart));

  gk_startcputimer(IOTmr);
  WriteMeshPartition(argv[1], nparts, ne, epart, nn, npart);
  gk_stopcputimer(IOTmr);


  mprintf("\nTiming Information --------------------------------------------------\n");
  mprintf("  I/O:          \t\t %7.3f\n", gk_getcputimer(IOTmr));
  mprintf("  Partitioning: \t\t %7.3f\n", gk_getcputimer(DUALTmr));
  mprintf("**********************************************************************\n");

/*
  graph.nvtxs = ne;
  graph.xadj = idxmalloc(ne+1, "xadj");
  graph.vwgt = idxsmalloc(ne, 1, "vwgt");
  graph.adjncy = idxmalloc(10*ne, "adjncy");
  graph.adjwgt = idxsmalloc(10*ne, 1, "adjncy");

  METIS_MeshToDual(&ne, &nn, elmnts, &etype, &numflag, graph.xadj, graph.adjncy);

  ComputePartitionInfo(&graph, nparts, epart);

  gk_free((void **)&graph.xadj, &graph.adjncy, &graph.vwgt, &graph.adjwgt, LTERM);
*/

  gk_free((void **)&elmnts, &epart, &npart, &metype, &weights,  LTERM);

}
/*************************************************************************
* 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;
}
Example #4
0
/*************************************************************************
* Let the game begin
**************************************************************************/
int main(int argc, char *argv[])
{
  idxtype i, options[10];
  idxtype *perm, *iperm;
  GraphType graph;
  char filename[256];
  idxtype numflag = 0, wgtflag;
  double TOTALTmr, METISTmr, IOTmr, SMBTmr;


  if (argc != 2) {
    mprintf("Usage: %s <GraphFile>\n",argv[0]);
    exit(0);
  }
    
  strcpy(filename, argv[1]);

  gk_clearcputimer(TOTALTmr);
  gk_clearcputimer(METISTmr);
  gk_clearcputimer(IOTmr);
  gk_clearcputimer(SMBTmr);

  gk_startcputimer(TOTALTmr);
  gk_startcputimer(IOTmr);
  ReadGraph(&graph, filename, &wgtflag);
  if (graph.nvtxs <= 0) {
    mprintf("Empty graph. Nothing to do.\n");
    exit(0);
  }
  if (graph.ncon != 1) {
    mprintf("Ordering can only be applied to graphs with one constraint.\n");
    exit(0);
  }
  gk_stopcputimer(IOTmr);

  /* Ordering does not use weights! */
  gk_free((void **)&graph.vwgt, &graph.adjwgt, LTERM);

  mprintf("**********************************************************************\n");
  mprintf("%s", METISTITLE);
  mprintf("Graph Information ---------------------------------------------------\n");
  mprintf("  Name: %s, #Vertices: %D, #Edges: %D\n\n", filename, graph.nvtxs, graph.nedges/2);
  mprintf("Node-Based Ordering... ----------------------------------------------\n");

  perm = idxmalloc(graph.nvtxs, "main: perm");
  iperm = idxmalloc(graph.nvtxs, "main: iperm");
  options[0] = 0;

  gk_startcputimer(METISTmr);
  METIS_NodeND(&graph.nvtxs, graph.xadj, graph.adjncy, &numflag, options, perm, iperm);
  gk_stopcputimer(METISTmr);

  gk_startcputimer(IOTmr);
  WritePermutation(filename, iperm, graph.nvtxs); 
  gk_stopcputimer(IOTmr);

  gk_startcputimer(SMBTmr);
  ComputeFillIn(&graph, iperm);
  gk_stopcputimer(SMBTmr);

  gk_stopcputimer(TOTALTmr);

  mprintf("\nTiming Information --------------------------------------------------\n");
  mprintf("  I/O:                     \t %7.3f\n", gk_getcputimer(IOTmr));
  mprintf("  Ordering:                \t %7.3f   (ONMETIS time)\n", gk_getcputimer(METISTmr));
  mprintf("  Symbolic Factorization:  \t %7.3f\n", gk_getcputimer(SMBTmr));
  mprintf("  Total:                   \t %7.3f\n", gk_getcputimer(TOTALTmr));
  mprintf("**********************************************************************\n");


  gk_free((void **)&graph.xadj, &graph.adjncy, &perm, &iperm, LTERM);
}