File: mkmetis.c

package info (click to toggle)
metis-edf 4.1-2-4
  • links: PTS, VCS
  • area: non-free
  • in suites: bookworm, bullseye, buster, sid, trixie
  • size: 3,696 kB
  • sloc: ansic: 15,702; makefile: 121; sh: 100; fortran: 61
file content (123 lines) | stat: -rw-r--r-- 3,997 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 /* 
  * Copyright 1997, Regents of the University of Minnesota 
  * 
  * mkmetis.c 
  * 
  * This file contains the top level routines for the multilevel k-way partitioning 
  * algorithm KMETIS. 
  * 
  * Started 7/28/97 
  * George 
  * 
  * $Id: mkmetis.c,v 1.2 1998/11/27 18:25:09 karypis Exp $ 
  * 
  */ 

 #include <metis.h> 



 /************************************************************************* 
 * This function is the entry point for KWMETIS 
 **************************************************************************/ 
 void METIS_mCPartGraphKway(long *nvtxs, long *ncon, idxtype *xadj, idxtype *adjncy,  
                           idxtype *vwgt, idxtype *adjwgt, long *wgtflag, long *numflag,  
                           long *nparts, float *rubvec, long *options, long *edgecut,  
                           idxtype *part) 
 { 
   long i, j; 
   GraphType graph; 
   CtrlType ctrl; 

   if (*numflag == 1) 
     Change2CNumbering(*nvtxs, xadj, adjncy); 

   SetUpGraph(&graph, OP_KMETIS, *nvtxs, *ncon, xadj, adjncy, vwgt, adjwgt, *wgtflag); 

   if (options[0] == 0) {  /* Use the default parameters */ 
     ctrl.CType  = McKMETIS_CTYPE; 
     ctrl.IType  = McKMETIS_ITYPE; 
     ctrl.RType  = McKMETIS_RTYPE; 
     ctrl.dbglvl = McKMETIS_DBGLVL; 
   } 
   else { 
     ctrl.CType  = options[OPTION_CTYPE]; 
     ctrl.IType  = options[OPTION_ITYPE]; 
     ctrl.RType  = options[OPTION_RTYPE]; 
     ctrl.dbglvl = options[OPTION_DBGLVL]; 
   } 
   ctrl.optype = OP_KMETIS; 
   ctrl.CoarsenTo = amax((*nvtxs)/(20*ilog2(*nparts)), 30*(*nparts)); 

   ctrl.nmaxvwgt = 1.5/(1.0*ctrl.CoarsenTo); 

   InitRandom(-1); 

   AllocateWorkSpace(&ctrl, &graph, *nparts); 

   IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl)); 
   IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr)); 

   *edgecut = MCMlevelKWayPartitioning(&ctrl, &graph, *nparts, part, rubvec); 

   IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr)); 
   IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl)); 

   FreeWorkSpace(&ctrl, &graph); 

   if (*numflag == 1) 
     Change2FNumbering(*nvtxs, xadj, adjncy, part); 
 } 


 /************************************************************************* 
 * This function takes a graph and produces a bisection of it 
 **************************************************************************/ 
 long MCMlevelKWayPartitioning(CtrlType *ctrl, GraphType *graph, long nparts, idxtype *part,  
       float *rubvec) 
 { 
   long i, j, nvtxs; 
   GraphType *cgraph; 
   long options[10], edgecut; 

   cgraph = MCCoarsen2Way(ctrl, graph); 

   IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->InitPartTmr)); 
   MocAllocateKWayPartitionMemory(ctrl, cgraph, nparts); 

   options[0] = 1;  
   options[OPTION_CTYPE] = MATCH_SBHEM_INFNORM; 
   options[OPTION_ITYPE] = IPART_RANDOM; 
   options[OPTION_RTYPE] = RTYPE_FM; 
   options[OPTION_DBGLVL] = 0; 

   /* Determine what you will use as the initial partitioner, based on tolerances */ 
   for (i=0; i<graph->ncon; i++) { 
     if (rubvec[i] > 1.2) 
       break; 
   } 
   if (i == graph->ncon) 
     METIS_mCPartGraphRecursiveInternal(&cgraph->nvtxs, &cgraph->ncon,  
           cgraph->xadj, cgraph->adjncy, cgraph->nvwgt, cgraph->adjwgt, &nparts,  
           options, &edgecut, cgraph->where); 
   else 
     METIS_mCHPartGraphRecursiveInternal(&cgraph->nvtxs, &cgraph->ncon,  
           cgraph->xadj, cgraph->adjncy, cgraph->nvwgt, cgraph->adjwgt, &nparts,  
           rubvec, options, &edgecut, cgraph->where); 


   IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->InitPartTmr)); 
   IFSET(ctrl->dbglvl, DBG_IPART, printf("Initial %ld-way partitioning cut: %ld\n", nparts, edgecut)); 

   IFSET(ctrl->dbglvl, DBG_KWAYPINFO, ComputePartitionInfo(cgraph, nparts, cgraph->where)); 

   MocRefineKWayHorizontal(ctrl, graph, cgraph, nparts, rubvec); 

   idxcopy(graph->nvtxs, graph->where, part); 

   GKfree(&graph->nvwgt, &graph->npwgts, &graph->gdata, &graph->rdata, LTERM); 

   return graph->mincut; 

 }