source: inundation/pymetis/metis-4.0/Programs/pmetis.c @ 3031

Last change on this file since 3031 was 2051, checked in by jack, 19 years ago

Python interface to metis. Currently provides only the
METIS_PartMeshNodal function, since that is what is currently needed for partitioning.
Module name is metis.

File size: 2.9 KB
Line 
1/*
2 * Copyright 1997, Regents of the University of Minnesota
3 *
4 * pmetis.c
5 *
6 * This file contains the driving routine for multilevel method
7 *
8 * Started 8/28/94
9 * George
10 *
11 * $Id: pmetis.c,v 1.1 1998/11/27 17:59:39 karypis Exp $
12 *
13 */
14
15#include <metis.h>
16
17
18
19/*************************************************************************
20* Let the game begin
21**************************************************************************/
22main(int argc, char *argv[])
23{
24  int i, nparts, options[10];
25  idxtype *part;
26  float lbvec[MAXNCON];
27  GraphType graph;
28  char filename[256];
29  int numflag = 0, wgtflag = 0, edgecut;
30  timer TOTALTmr, METISTmr, IOTmr;
31
32
33  if (argc != 3) {
34    printf("Usage: %s <GraphFile> <Nparts>\n",argv[0]);
35    exit(0);
36  }
37   
38  strcpy(filename, argv[1]);
39  nparts = atoi(argv[2]);
40
41  if (nparts < 2) {
42    printf("The number of partitions should be greater than 1!\n");
43    exit(0);
44  }
45
46  cleartimer(TOTALTmr);
47  cleartimer(METISTmr);
48  cleartimer(IOTmr);
49
50  starttimer(TOTALTmr);
51  starttimer(IOTmr);
52  ReadGraph(&graph, filename, &wgtflag);
53  if (graph.nvtxs <= 0) {
54    printf("Empty graph. Nothing to do.\n");
55    exit(0);
56  }
57  stoptimer(IOTmr);
58
59  printf("**********************************************************************\n");
60  printf("%s", METISTITLE);
61  printf("Graph Information ---------------------------------------------------\n");
62  printf("  Name: %s, #Vertices: %d, #Edges: %d, #Parts: %d\n", filename, graph.nvtxs, graph.nedges/2, nparts);
63  if (graph.ncon > 1)
64    printf("  Balancing Constraints: %d\n", graph.ncon);
65  printf("\nRecursive Partitioning... -------------------------------------------\n");
66
67  part = idxmalloc(graph.nvtxs, "main: part");
68  options[0] = 0;
69
70  starttimer(METISTmr);
71  if (graph.ncon == 1) {
72    METIS_PartGraphRecursive(&graph.nvtxs, graph.xadj, graph.adjncy, graph.vwgt, graph.adjwgt, 
73          &wgtflag, &numflag, &nparts, options, &edgecut, part);
74  }
75  else {
76    METIS_mCPartGraphRecursive(&graph.nvtxs, &graph.ncon, graph.xadj, graph.adjncy, graph.vwgt, 
77          graph.adjwgt, &wgtflag, &numflag, &nparts, options, &edgecut, part);
78  }
79
80  stoptimer(METISTmr);
81
82  ComputePartitionBalance(&graph, nparts, part, lbvec);
83
84  printf("  %d-way Edge-Cut: %7d, Balance: ", nparts, edgecut);
85  for (i=0; i<graph.ncon; i++)
86    printf("%5.2f ", lbvec[i]);
87  printf("\n");
88
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   (PMETIS 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
Note: See TracBrowser for help on using the repository browser.