Path: blob/devel/elmergrid/src/metis-5.1.0/programs/m2gmetis.c
3206 views
/*1* Copyright 1994-2011, Regents of the University of Minnesota2*3* m2gmetis.c4*5* Drivers for the mesh-to-graph coversion routines6*7* Started 5/28/118* George9*10* $Id: m2gmetis.c 10498 2011-07-06 16:41:38Z karypis $11*12*/1314#include "metisbin.h"15161718/*************************************************************************/19/*! Let the game begin! */20/*************************************************************************/21int main(int argc, char *argv[])22{23mesh_t *mesh;24graph_t *graph;25params_t *params;26int status=0;2728params = parse_cmdline(argc, argv);2930gk_startcputimer(params->iotimer);31mesh = ReadMesh(params);3233gk_stopcputimer(params->iotimer);3435if (mesh->ncon > 1) {36printf("*** Meshes with more than one balancing constraint are not supported yet.\n");37exit(0);38}3940M2GPrintInfo(params, mesh);4142graph = CreateGraph();4344gk_malloc_init();45gk_startcputimer(params->parttimer);4647switch (params->gtype) {48case METIS_GTYPE_DUAL:49status = METIS_MeshToDual(&mesh->ne, &mesh->nn, mesh->eptr, mesh->eind,50¶ms->ncommon, ¶ms->numflag, &graph->xadj, &graph->adjncy);5152if (status == METIS_OK) {53graph->nvtxs = mesh->ne;54graph->nedges = graph->xadj[graph->nvtxs];55graph->ncon = 1;56}57break;5859case METIS_GTYPE_NODAL:60status = METIS_MeshToNodal(&mesh->ne, &mesh->nn, mesh->eptr, mesh->eind,61¶ms->numflag, &graph->xadj, &graph->adjncy);6263if (status == METIS_OK) {64graph->nvtxs = mesh->nn;65graph->nedges = graph->xadj[graph->nvtxs];66graph->ncon = 1;67}68break;69}7071gk_stopcputimer(params->parttimer);72if (gk_GetCurMemoryUsed() != 0)73printf("***It seems that Metis did not free all of its memory! Report this.\n");74params->maxmemory = gk_GetMaxMemoryUsed();75gk_malloc_cleanup(0);7677if (status != METIS_OK) {78printf("\n***Metis returned with an error.\n");79}80else {81/* Write the graph */82gk_startcputimer(params->iotimer);83WriteGraph(graph, params->outfile);84gk_stopcputimer(params->iotimer);8586M2GReportResults(params, mesh, graph);87}8889FreeGraph(&graph);90FreeMesh(&mesh);91gk_free((void **)¶ms->filename, ¶ms->outfile, ¶ms, LTERM);92}939495/*************************************************************************/96/*! This function prints run parameters */97/*************************************************************************/98void M2GPrintInfo(params_t *params, mesh_t *mesh)99{100printf("******************************************************************************\n");101printf("%s", METISTITLE);102printf(" (HEAD: %s, Built on: %s, %s)\n", SVNINFO, __DATE__, __TIME__);103printf(" size of idx_t: %zubits, real_t: %zubits, idx_t *: %zubits\n",1048*sizeof(idx_t), 8*sizeof(real_t), 8*sizeof(idx_t *));105printf("\n");106printf("Mesh Information ------------------------------------------------------------\n");107printf(" Name: %s, #Elements: %"PRIDX", #Nodes: %"PRIDX"\n",108params->filename, mesh->ne, mesh->nn);109110printf("Options ---------------------------------------------------------------------\n");111printf(" gtype=%s, ncommon=%"PRIDX", outfile=%s\n",112gtypenames[params->gtype], params->ncommon, params->outfile);113114printf("\n");115}116117118/*************************************************************************/119/*! This function does any post-metis reporting */120/*************************************************************************/121void M2GReportResults(params_t *params, mesh_t *mesh, graph_t *graph)122{123124gk_startcputimer(params->reporttimer);125126printf(" - #nvtxs: %"PRIDX", #edges: %"PRIDX"\n", graph->nvtxs, graph->nedges);127128gk_stopcputimer(params->reporttimer);129130131printf("\nTiming Information ----------------------------------------------------------\n");132printf(" I/O: \t\t %7.3"PRREAL" sec\n", gk_getcputimer(params->iotimer));133printf(" Partitioning: \t\t %7.3"PRREAL" sec (METIS time)\n", gk_getcputimer(params->parttimer));134printf(" Reporting: \t\t %7.3"PRREAL" sec\n", gk_getcputimer(params->reporttimer));135printf("\nMemory Information ----------------------------------------------------------\n");136printf(" Max memory used:\t\t %7.3"PRREAL" MB\n", (real_t)(params->maxmemory/(1024.0*1024.0)));137printf("******************************************************************************\n");138139}140141142