File: srefine.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 (169 lines) | stat: -rw-r--r-- 5,049 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
 /* 
  * Copyright 1997, Regents of the University of Minnesota 
  * 
  * srefine.c 
  * 
  * This file contains code for the separator refinement algortihms 
  * 
  * Started 8/1/97 
  * George 
  * 
  * $Id: srefine.c,v 1.1 1998/11/27 17:59:30 karypis Exp $ 
  * 
  */ 

 #include <metis.h> 


 /************************************************************************* 
 * This function is the entry point of the separator refinement 
 **************************************************************************/ 
 void Refine2WayNode(CtrlType *ctrl, GraphType *orggraph, GraphType *graph, float ubfactor) 
 { 

   IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->UncoarsenTmr)); 

   for (;;) { 
     IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->RefTmr)); 
     if (ctrl->RType != 15) 
       FM_2WayNodeBalance(ctrl, graph, ubfactor);  

     switch (ctrl->RType) { 
       case 1: 
         FM_2WayNodeRefine(ctrl, graph, ubfactor, 8);  
         break; 
       case 2: 
         FM_2WayNodeRefine_OneSided(ctrl, graph, ubfactor, 8);  
         break; 
       case 3: 
         FM_2WayNodeRefine(ctrl, graph, ubfactor, 8);  
         FM_2WayNodeRefine_OneSided(ctrl, graph, ubfactor, 8);  
         break; 
       case 4: 
         FM_2WayNodeRefine_OneSided(ctrl, graph, ubfactor, 8);  
         FM_2WayNodeRefine(ctrl, graph, ubfactor, 8);  
         break; 
       case 5: 
         FM_2WayNodeRefineEqWgt(ctrl, graph, 8);  
         break; 
     } 
     IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->RefTmr)); 

     if (graph == orggraph)  
       break; 

     graph = graph->finer; 
     IFSET(ctrl->dbglvl, DBG_TIME, starttimer(ctrl->ProjectTmr)); 
     Project2WayNodePartition(ctrl, graph); 
     IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->ProjectTmr)); 
   } 

   IFSET(ctrl->dbglvl, DBG_TIME, stoptimer(ctrl->UncoarsenTmr)); 
 } 


 /************************************************************************* 
 * This function allocates memory for 2-way edge refinement 
 **************************************************************************/ 
 void Allocate2WayNodePartitionMemory(CtrlType *ctrl, GraphType *graph) 
 { 
   long nvtxs, pad64; 

   nvtxs = graph->nvtxs; 

   pad64 = (3*nvtxs+3)%2; 

   graph->rdata = idxmalloc(3*nvtxs+3+(sizeof(NRInfoType)/sizeof(idxtype))*nvtxs+pad64, "Allocate2WayPartitionMemory: rdata"); 
   graph->pwgts          = graph->rdata; 
   graph->where          = graph->rdata + 3; 
   graph->bndptr         = graph->rdata + nvtxs + 3; 
   graph->bndind         = graph->rdata + 2*nvtxs + 3; 
   graph->nrinfo         = (NRInfoType *)(graph->rdata + 3*nvtxs + 3 + pad64); 
 } 



 /************************************************************************* 
 * This function computes the initial id/ed  
 **************************************************************************/ 
 void Compute2WayNodePartitionParams(CtrlType *ctrl, GraphType *graph) 
 { 
   long i, j, k, l, nvtxs, nbnd; 
   idxtype *xadj, *adjncy, *adjwgt, *vwgt; 
   idxtype *where, *pwgts, *bndind, *bndptr, *edegrees; 
   NRInfoType *rinfo; 
   long me, other; 

   nvtxs = graph->nvtxs; 
   xadj = graph->xadj; 
   vwgt = graph->vwgt; 
   adjncy = graph->adjncy; 
   adjwgt = graph->adjwgt; 

   where = graph->where; 
   rinfo = graph->nrinfo; 
   pwgts = idxset(3, 0, graph->pwgts); 
   bndind = graph->bndind; 
   bndptr = idxset(nvtxs, -1, graph->bndptr); 


   /*------------------------------------------------------------ 
   / Compute now the separator external degrees 
   /------------------------------------------------------------*/ 
   nbnd = 0; 
   for (i=0; i<nvtxs; i++) { 
     me = where[i]; 
     pwgts[me] += vwgt[i]; 

     ASSERT(me >=0 && me <= 2); 

     if (me == 2) { /* If it is on the separator do some computations */ 
       BNDInsert(nbnd, bndind, bndptr, i); 

       edegrees = rinfo[i].edegrees; 
       edegrees[0] = edegrees[1] = 0; 

       for (j=xadj[i]; j<xadj[i+1]; j++) { 
         other = where[adjncy[j]]; 
         if (other != 2) 
           edegrees[other] += vwgt[adjncy[j]]; 
       } 
     } 
   } 

   ASSERT(CheckNodeBnd(graph, nbnd)); 

   graph->mincut = pwgts[2]; 
   graph->nbnd = nbnd; 
 } 


 /************************************************************************* 
 * This function computes the initial id/ed  
 **************************************************************************/ 
 void Project2WayNodePartition(CtrlType *ctrl, GraphType *graph) 
 { 
   long i, j, nvtxs; 
   idxtype *cmap, *where, *cwhere; 
   GraphType *cgraph; 

   cgraph = graph->coarser; 
   cwhere = cgraph->where; 

   nvtxs = graph->nvtxs; 
   cmap = graph->cmap; 

   Allocate2WayNodePartitionMemory(ctrl, graph); 
   where = graph->where; 
    
   /* Project the partition */ 
   for (i=0; i<nvtxs; i++) { 
     where[i] = cwhere[cmap[i]]; 
     ASSERTP(where[i] >= 0 && where[i] <= 2, ("%ld %ld %ld %ld\n", i, cmap[i], where[i], cwhere[cmap[i]])); 
   } 

   FreeGraph(graph->coarser); 
   graph->coarser = NULL; 

   Compute2WayNodePartitionParams(ctrl, graph); 
 }