Esempio n. 1
0
/*************************************************************************
* This function is my wrapper around realloc
**************************************************************************/
void *gk_realloc(void *oldptr, size_t nbytes, char *msg)
{
  void *ptr=NULL;

  if (nbytes == 0)
    nbytes++;  /* Force mallocs to actually allocate some memory */

  /* remove this memory de-allocation */
  if (gkmcore != NULL && oldptr != NULL) gk_gkmcoreDel(gkmcore, oldptr);

  ptr = (void *)realloc(oldptr, nbytes);

  if (ptr == NULL) {
    fprintf(stderr, "   Maximum memory used: %10zu bytes\n", gk_GetMaxMemoryUsed());
    fprintf(stderr, "   Current memory used: %10zu bytes\n", gk_GetCurMemoryUsed());
    gk_errexit(SIGMEM, "***Memory realloc failed for %s. " "Requested size: %zu bytes", 
        msg, nbytes);
    return NULL;
  }

  /* add this memory allocation */
  if (gkmcore != NULL) gk_gkmcoreAdd(gkmcore, GK_MOPT_HEAP, nbytes, ptr);

  return ptr;
}
Esempio n. 2
0
void *gk_malloc(size_t nbytes, char *msg)
{
  void *ptr=NULL;

  if (nbytes == 0)
    nbytes++;  /* Force mallocs to actually allocate some memory */

  ptr = (void *)malloc(nbytes);

  if (ptr == NULL) {
    fprintf(stderr, "   Current memory used:  %10zu bytes\n", gk_GetCurMemoryUsed());
    fprintf(stderr, "   Maximum memory used:  %10zu bytes\n", gk_GetMaxMemoryUsed());
    gk_errexit(SIGMEM, "***Memory allocation failed for %s. Requested size: %zu bytes", 
        msg, nbytes);
    return NULL;
  }

  /* add this memory allocation */
  if (gkmcore != NULL) gk_gkmcoreAdd(gkmcore, GK_MOPT_HEAP, nbytes, ptr);

  /* zero-out the allocated space */
#ifndef NDEBUG
  memset(ptr, 0, nbytes);
#endif

  return ptr;
}
Esempio n. 3
0
void print_final_info(params_t *params)
{
  printf("\n");
  printf("Memory Usage Information -----------------------------------------------------\n");
  printf("   Maximum memory used:              %10zd bytes\n", (ssize_t) gk_GetMaxMemoryUsed());
  printf("   Current memory used:              %10zd bytes\n", (ssize_t) gk_GetCurMemoryUsed());
  printf("********************************************************************************\n");
}
Esempio n. 4
0
File: rbbdf.c Progetto: 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;
}
Esempio n. 5
0
idx_t* gpmetis( int argc, char **argv )
/*************************************************************************/
/*! Let the game begin! */
/*************************************************************************/
//int main(int argc, char *argv[])
{
  idx_t i;
  char *curptr, *newptr;
  idx_t options[METIS_NOPTIONS];
  graph_t *graph;
  idx_t *part;
  idx_t objval;
  params_t *params;
  int status=0;

  gk_optind = 0;

  //printf( "argc: %d\n", argc );
  //printf( "gk_optind %d\n", gk_optind );
  fflush( stdout );

    for( i = 0; i < argc; i++ )
    {
        //printf( "%s*\n", argv[ i ] );
    }


  params = parse_cmdline(argc, argv);
  //printf( "gk_optind %d\n", gk_optind );
  //fflush( stdout );
  //return NULL;

  gk_startcputimer(params->iotimer);
  graph = ReadGraph(params);

  ReadTPwgts(params, graph->ncon);
  gk_stopcputimer(params->iotimer);

  /* Check if the graph is contiguous */
  if (params->contig && !IsConnected(graph, 0)) {
    printf("***The input graph is not contiguous.\n"
           "***The specified -contig option will be ignored.\n");
    params->contig = 0;
  }

  /* Get ubvec if supplied */
  if (params->ubvecstr) {
    params->ubvec = rmalloc(graph->ncon, "main");
    curptr = params->ubvecstr;
    for (i=0; i<graph->ncon; i++) {
      params->ubvec[i] = strtoreal(curptr, &newptr);
      if (curptr == newptr)
        errexit("Error parsing entry #%"PRIDX" of ubvec [%s] (possibly missing).\n",
            i, params->ubvecstr);
      curptr = newptr;
    }
  }

  /* Setup iptype */
  if (params->iptype == -1) {
    if (params->ptype == METIS_PTYPE_RB) {
      if (graph->ncon == 1)
        params->iptype = METIS_IPTYPE_GROW;
      else
        params->iptype = METIS_IPTYPE_RANDOM;
    }
  }

  GPPrintInfo(params, graph);

  part = imalloc(graph->nvtxs, "main: part");

  METIS_SetDefaultOptions(options);
  options[METIS_OPTION_OBJTYPE] = params->objtype;
  options[METIS_OPTION_CTYPE]   = params->ctype;
  options[METIS_OPTION_IPTYPE]  = params->iptype;
  options[METIS_OPTION_RTYPE]   = params->rtype;
  options[METIS_OPTION_MINCONN] = params->minconn;
  options[METIS_OPTION_CONTIG]  = params->contig;
  options[METIS_OPTION_SEED]    = params->seed;
  options[METIS_OPTION_NITER]   = params->niter;
  options[METIS_OPTION_NCUTS]   = params->ncuts;
  options[METIS_OPTION_UFACTOR] = params->ufactor;
  options[METIS_OPTION_DBGLVL]  = params->dbglvl;

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

  switch (params->ptype) {
    case METIS_PTYPE_RB:
      status = METIS_PartGraphRecursive(&graph->nvtxs, &graph->ncon, graph->xadj,
                   graph->adjncy, graph->vwgt, graph->vsize, graph->adjwgt,
                   &params->nparts, params->tpwgts, params->ubvec, options,
                   &objval, part);
      break;

    case METIS_PTYPE_KWAY:
      status = METIS_PartGraphKway(&graph->nvtxs, &graph->ncon, graph->xadj,
                   graph->adjncy, graph->vwgt, graph->vsize, graph->adjwgt,
                   &params->nparts, params->tpwgts, params->ubvec, options,
                   &objval, part);
      break;

  }

  gk_stopcputimer(params->parttimer);

  if (gk_GetCurMemoryUsed() != 0)
    printf("***It seems that Metis did not free all of its memory! Report this.\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 solution */
      gk_startcputimer(params->iotimer);
      WritePartition(params->filename, part, graph->nvtxs, params->nparts);
      gk_stopcputimer(params->iotimer);
    }

    GPReportResults(params, graph, part, objval);
  }

  idx_t *r_part = ( idx_t* ) calloc( graph->nvtxs, sizeof( idx_t ) );

  for( i = 0; i < graph->nvtxs; i++ )
  {
       r_part[ i ] = part[ i ];
  }

  FreeGraph(&graph);
  gk_free((void **)&part, LTERM);
  gk_free((void **)&params->filename, &params->tpwgtsfile, &params->tpwgts,
      &params->ubvecstr, &params->ubvec, &params, LTERM);

  return r_part;
}