00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 #include "metisbin.h"
00016 
00017 
00018 
00019 
00021 
00022 int main(int argc, char *argv[])
00023 {
00024   mesh_t *mesh;
00025   graph_t *graph;
00026   params_t *params;
00027   int status=0;
00028 
00029   params = parse_cmdline(argc, argv);
00030 
00031   gk_startcputimer(params->iotimer);
00032   mesh = ReadMesh(params);
00033 
00034   gk_stopcputimer(params->iotimer);
00035 
00036   if (mesh->ncon > 1) {
00037     printf("*** Meshes with more than one balancing constraint are not supported yet.\n");
00038     exit(0);
00039   }
00040 
00041   M2GPrintInfo(params, mesh);
00042 
00043   graph = CreateGraph();
00044 
00045   gk_malloc_init();
00046   gk_startcputimer(params->parttimer);
00047 
00048   switch (params->gtype) {
00049     case METIS_GTYPE_DUAL:
00050       status = METIS_MeshToDual(&mesh->ne, &mesh->nn, mesh->eptr, mesh->eind, 
00051                    ¶ms->ncommon, ¶ms->numflag, &graph->xadj, &graph->adjncy);
00052 
00053       if (status == METIS_OK) {
00054         graph->nvtxs  = mesh->ne;
00055         graph->nedges = graph->xadj[graph->nvtxs]; 
00056         graph->ncon   = 1;
00057       }
00058       break;
00059 
00060     case METIS_GTYPE_NODAL:
00061       status = METIS_MeshToNodal(&mesh->ne, &mesh->nn, mesh->eptr, mesh->eind, 
00062                    ¶ms->numflag, &graph->xadj, &graph->adjncy);
00063 
00064       if (status == METIS_OK) {
00065         graph->nvtxs  = mesh->nn;
00066         graph->nedges = graph->xadj[graph->nvtxs]; 
00067         graph->ncon   = 1;
00068       }
00069       break;
00070   }
00071 
00072   gk_stopcputimer(params->parttimer);
00073   if (gk_GetCurMemoryUsed() != 0)
00074         printf("***It seems that Metis did not free all of its memory! Report this.\n");
00075   params->maxmemory = gk_GetMaxMemoryUsed();
00076   gk_malloc_cleanup(0);
00077 
00078   if (status != METIS_OK) {
00079     printf("\n***Metis returned with an error.\n");
00080   }
00081   else {
00082     
00083     gk_startcputimer(params->iotimer);
00084     WriteGraph(graph, params->outfile);
00085     gk_stopcputimer(params->iotimer);
00086 
00087     M2GReportResults(params, mesh, graph);
00088   }
00089 
00090   FreeGraph(&graph);
00091   FreeMesh(&mesh);
00092   gk_free((void **)¶ms->filename, ¶ms->outfile, ¶ms, LTERM);
00093 }
00094 
00095 
00096 
00098 
00099 void M2GPrintInfo(params_t *params, mesh_t *mesh)
00100 { 
00101   printf("******************************************************************************\n");
00102   printf("%s", METISTITLE);
00103   printf(" (HEAD: %s, Built on: %s, %s)\n", SVNINFO, __DATE__, __TIME__);
00104   printf(" size of idx_t: %zubits, real_t: %zubits, idx_t *: %zubits\n", 
00105       8*sizeof(idx_t), 8*sizeof(real_t), 8*sizeof(idx_t *));
00106   printf("\n");
00107   printf("Mesh Information ------------------------------------------------------------\n");
00108   printf(" Name: %s, #Elements: %"PRIDX", #Nodes: %"PRIDX"\n", 
00109       params->filename, mesh->ne, mesh->nn); 
00110   
00111   printf("Options ---------------------------------------------------------------------\n");
00112   printf(" gtype=%s, ncommon=%"PRIDX", outfile=%s\n", 
00113       gtypenames[params->gtype], params->ncommon, params->outfile);
00114 
00115   printf("\n");
00116 }
00117 
00118 
00119 
00121 
00122 void M2GReportResults(params_t *params, mesh_t *mesh, graph_t *graph)
00123 { 
00124 
00125   gk_startcputimer(params->reporttimer);
00126 
00127   printf(" - #nvtxs: %"PRIDX", #edges: %"PRIDX"\n", graph->nvtxs, graph->nedges);
00128 
00129   gk_stopcputimer(params->reporttimer);
00130 
00131 
00132   printf("\nTiming Information ----------------------------------------------------------\n");
00133   printf("  I/O:          \t\t %7.3"PRREAL" sec\n", gk_getcputimer(params->iotimer));
00134   printf("  Partitioning: \t\t %7.3"PRREAL" sec   (METIS time)\n", gk_getcputimer(params->parttimer));
00135   printf("  Reporting:    \t\t %7.3"PRREAL" sec\n", gk_getcputimer(params->reporttimer));
00136   printf("\nMemory Information ----------------------------------------------------------\n");
00137   printf("  Max memory used:\t\t %7.3"PRREAL" MB\n", (real_t)(params->maxmemory/(1024.0*1024.0)));
00138   printf("******************************************************************************\n");
00139 
00140 }