[2051] | 1 | /* |
---|
| 2 | * Copyright 1997, Regents of the University of Minnesota |
---|
| 3 | * |
---|
| 4 | * kmetis.c |
---|
| 5 | * |
---|
| 6 | * This file contains the driving routine for kmetis |
---|
| 7 | * |
---|
| 8 | * Started 8/28/94 |
---|
| 9 | * George |
---|
| 10 | * |
---|
| 11 | * $Id: kmetis.c,v 1.1 1998/11/27 17:59:35 karypis Exp $ |
---|
| 12 | * |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #include <metis.h> |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | /************************************************************************* |
---|
| 20 | * Let the game begin |
---|
| 21 | **************************************************************************/ |
---|
| 22 | main(int argc, char *argv[]) |
---|
| 23 | { |
---|
| 24 | int i, nparts, options[10]; |
---|
| 25 | idxtype *part; |
---|
| 26 | float rubvec[MAXNCON], lbvec[MAXNCON]; |
---|
| 27 | GraphType graph; |
---|
| 28 | char filename[256]; |
---|
| 29 | int numflag = 0, wgtflag = 0, edgecut; |
---|
| 30 | timer TOTALTmr, METISTmr, IOTmr; |
---|
| 31 | |
---|
| 32 | if (argc != 3) { |
---|
| 33 | printf("Usage: %s <GraphFile> <Nparts>\n",argv[0]); |
---|
| 34 | exit(0); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | strcpy(filename, argv[1]); |
---|
| 38 | nparts = atoi(argv[2]); |
---|
| 39 | |
---|
| 40 | if (nparts < 2) { |
---|
| 41 | printf("The number of partitions should be greater than 1!\n"); |
---|
| 42 | exit(0); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | cleartimer(TOTALTmr); |
---|
| 46 | cleartimer(METISTmr); |
---|
| 47 | cleartimer(IOTmr); |
---|
| 48 | |
---|
| 49 | starttimer(TOTALTmr); |
---|
| 50 | starttimer(IOTmr); |
---|
| 51 | ReadGraph(&graph, filename, &wgtflag); |
---|
| 52 | if (graph.nvtxs <= 0) { |
---|
| 53 | printf("Empty graph. Nothing to do.\n"); |
---|
| 54 | exit(0); |
---|
| 55 | } |
---|
| 56 | stoptimer(IOTmr); |
---|
| 57 | |
---|
| 58 | printf("**********************************************************************\n"); |
---|
| 59 | printf("%s", METISTITLE); |
---|
| 60 | printf("Graph Information ---------------------------------------------------\n"); |
---|
| 61 | printf(" Name: %s, #Vertices: %d, #Edges: %d, #Parts: %d\n", filename, graph.nvtxs, graph.nedges/2, nparts); |
---|
| 62 | if (graph.ncon > 1) |
---|
| 63 | printf(" Balancing Constraints: %d\n", graph.ncon); |
---|
| 64 | printf("\nK-way Partitioning... -----------------------------------------------\n"); |
---|
| 65 | |
---|
| 66 | part = idxmalloc(graph.nvtxs, "main: part"); |
---|
| 67 | options[0] = 0; |
---|
| 68 | |
---|
| 69 | starttimer(METISTmr); |
---|
| 70 | if (graph.ncon == 1) { |
---|
| 71 | METIS_PartGraphKway(&graph.nvtxs, graph.xadj, graph.adjncy, graph.vwgt, graph.adjwgt, |
---|
| 72 | &wgtflag, &numflag, &nparts, options, &edgecut, part); |
---|
| 73 | } |
---|
| 74 | else { |
---|
| 75 | for (i=0; i<graph.ncon; i++) |
---|
| 76 | rubvec[i] = HORIZONTAL_IMBALANCE; |
---|
| 77 | |
---|
| 78 | METIS_mCPartGraphKway(&graph.nvtxs, &graph.ncon, graph.xadj, graph.adjncy, graph.vwgt, |
---|
| 79 | graph.adjwgt, &wgtflag, &numflag, &nparts, rubvec, options, &edgecut, part); |
---|
| 80 | } |
---|
| 81 | stoptimer(METISTmr); |
---|
| 82 | |
---|
| 83 | ComputePartitionBalance(&graph, nparts, part, lbvec); |
---|
| 84 | |
---|
| 85 | printf(" %d-way Edge-Cut: %7d, Balance: ", nparts, edgecut); |
---|
| 86 | for (i=0; i<graph.ncon; i++) |
---|
| 87 | printf("%5.2f ", lbvec[i]); |
---|
| 88 | printf("\n"); |
---|
| 89 | |
---|
| 90 | starttimer(IOTmr); |
---|
| 91 | WritePartition(filename, part, graph.nvtxs, nparts); |
---|
| 92 | stoptimer(IOTmr); |
---|
| 93 | stoptimer(TOTALTmr); |
---|
| 94 | |
---|
| 95 | printf("\nTiming Information --------------------------------------------------\n"); |
---|
| 96 | printf(" I/O: \t\t %7.3f\n", gettimer(IOTmr)); |
---|
| 97 | printf(" Partitioning: \t\t %7.3f (KMETIS time)\n", gettimer(METISTmr)); |
---|
| 98 | printf(" Total: \t\t %7.3f\n", gettimer(TOTALTmr)); |
---|
| 99 | printf("**********************************************************************\n"); |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | GKfree(&graph.xadj, &graph.adjncy, &graph.vwgt, &graph.adjwgt, &part, LTERM); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | |
---|