The R Project SVN R-packages

Rev

Rev 155 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 155 Rev 1128
1
/*
1
/*
2
 * Copyright 1997, Regents of the University of Minnesota
2
 * Copyright 1997, Regents of the University of Minnesota
3
 *
3
 *
4
 * debug.c
4
 * debug.c
5
 *
5
 *
6
 * This file contains code that performs self debuging
6
 * This file contains code that performs self debuging
7
 *
7
 *
8
 * Started 7/24/97
8
 * Started 7/24/97
9
 * George
9
 * George
10
 *
10
 *
11
 * $Id: debug.c,v 1.1 2003/12/31 21:32:30 bates Exp $
11
 * $Id: debug.c,v 1.1 2003/12/31 21:32:30 bates Exp $
12
 *
12
 *
13
 */
13
 */
14
 
14
 
15
#include <metis.h>
15
#include <metis.h>
16
 
16
 
17
/*************************************************************************
17
/*************************************************************************
18
* This function computes the cut given the graph and a where vector
18
* This function computes the cut given the graph and a where vector
19
**************************************************************************/
19
**************************************************************************/
20
int ComputeCut(GraphType *graph, idxtype *where)
20
int ComputeCut(GraphType *graph, idxtype *where)
21
{
21
{
22
  int i, j, cut;
22
  int i, j, cut;
23
 
23
 
24
  if (graph->adjwgt == NULL) {
24
  if (graph->adjwgt == NULL) {
25
    for (cut=0, i=0; i<graph->nvtxs; i++) {
25
    for (cut=0, i=0; i<graph->nvtxs; i++) {
26
      for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++)
26
      for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++)
27
        if (where[i] != where[graph->adjncy[j]])
27
        if (where[i] != where[graph->adjncy[j]])
28
          cut++;
28
          cut++;
29
    }
29
    }
30
  }
30
  }
31
  else {
31
  else {
32
    for (cut=0, i=0; i<graph->nvtxs; i++) {
32
    for (cut=0, i=0; i<graph->nvtxs; i++) {
33
      for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++)
33
      for (j=graph->xadj[i]; j<graph->xadj[i+1]; j++)
34
        if (where[i] != where[graph->adjncy[j]])
34
        if (where[i] != where[graph->adjncy[j]])
35
          cut += graph->adjwgt[j];
35
          cut += graph->adjwgt[j];
36
    }
36
    }
37
  }
37
  }
38
 
38
 
39
  return cut/2;
39
  return cut/2;
40
}
40
}
41
 
41
 
42
 
42
 
43
/*************************************************************************
43
/*************************************************************************
44
* This function checks whether or not the boundary information is correct
44
* This function checks whether or not the boundary information is correct
45
**************************************************************************/
45
**************************************************************************/
46
int CheckBnd(GraphType *graph) 
46
int CheckBnd(GraphType *graph) 
47
{
47
{
48
  int i, j, nvtxs, nbnd;
48
  int i, j, nvtxs, nbnd;
49
  idxtype *xadj, *adjncy, *where, *bndptr, *bndind;
49
  idxtype *xadj, *adjncy, *where, *bndptr, *bndind;
50
 
50
 
51
  nvtxs = graph->nvtxs;
51
  nvtxs = graph->nvtxs;
52
  xadj = graph->xadj;
52
  xadj = graph->xadj;
53
  adjncy = graph->adjncy;
53
  adjncy = graph->adjncy;
54
  where = graph->where;
54
  where = graph->where;
55
  bndptr = graph->bndptr;
55
  bndptr = graph->bndptr;
56
  bndind = graph->bndind;
56
  bndind = graph->bndind;
57
 
57
 
58
  for (nbnd=0, i=0; i<nvtxs; i++) {
58
  for (nbnd=0, i=0; i<nvtxs; i++) {
59
    if (xadj[i+1]-xadj[i] == 0)
59
    if (xadj[i+1]-xadj[i] == 0)
60
      nbnd++;   /* Islands are considered to be boundary vertices */
60
      nbnd++;   /* Islands are considered to be boundary vertices */
61
 
61
 
62
    for (j=xadj[i]; j<xadj[i+1]; j++) {
62
    for (j=xadj[i]; j<xadj[i+1]; j++) {
63
      if (where[i] != where[adjncy[j]]) {
63
      if (where[i] != where[adjncy[j]]) {
64
        nbnd++;
64
        nbnd++;
65
        ASSERT(bndptr[i] != -1);
65
        ASSERT(bndptr[i] != -1);
66
        ASSERT(bndind[bndptr[i]] == i);
66
        ASSERT(bndind[bndptr[i]] == i);
67
        break;
67
        break;
68
      }
68
      }
69
    }
69
    }
70
  }
70
  }
71
 
71
 
72
  ASSERTP(nbnd == graph->nbnd, ("%d %d\n", nbnd, graph->nbnd));
72
  ASSERTP(nbnd == graph->nbnd, ("%d %d\n", nbnd, graph->nbnd));
73
 
73
 
74
  return 1;
74
  return 1;
75
}
75
}
76
 
76
 
77
 
77
 
78
 
78
 
79
/*************************************************************************
79
/*************************************************************************
80
* This function checks whether or not the boundary information is correct
80
* This function checks whether or not the boundary information is correct
81
**************************************************************************/
81
**************************************************************************/
82
int CheckBnd2(GraphType *graph) 
82
int CheckBnd2(GraphType *graph) 
83
{
83
{
84
  int i, j, nvtxs, nbnd, id, ed;
84
  int i, j, nvtxs, nbnd, id, ed;
85
  idxtype *xadj, *adjncy, *where, *bndptr, *bndind;
85
  idxtype *xadj, *adjncy, *where, *bndptr, *bndind;
86
 
86
 
87
  nvtxs = graph->nvtxs;
87
  nvtxs = graph->nvtxs;
88
  xadj = graph->xadj;
88
  xadj = graph->xadj;
89
  adjncy = graph->adjncy;
89
  adjncy = graph->adjncy;
90
  where = graph->where;
90
  where = graph->where;
91
  bndptr = graph->bndptr;
91
  bndptr = graph->bndptr;
92
  bndind = graph->bndind;
92
  bndind = graph->bndind;
93
 
93
 
94
  for (nbnd=0, i=0; i<nvtxs; i++) {
94
  for (nbnd=0, i=0; i<nvtxs; i++) {
95
    id = ed = 0;
95
    id = ed = 0;
96
    for (j=xadj[i]; j<xadj[i+1]; j++) {
96
    for (j=xadj[i]; j<xadj[i+1]; j++) {
97
      if (where[i] != where[adjncy[j]]) 
97
      if (where[i] != where[adjncy[j]]) 
98
        ed += graph->adjwgt[j];
98
        ed += graph->adjwgt[j];
99
      else
99
      else
100
        id += graph->adjwgt[j];
100
        id += graph->adjwgt[j];
101
    }
101
    }
102
    if (ed - id >= 0 && xadj[i] < xadj[i+1]) {
102
    if (ed - id >= 0 && xadj[i] < xadj[i+1]) {
103
      nbnd++;
103
      nbnd++;
104
      ASSERTP(bndptr[i] != -1, ("%d %d %d\n", i, id, ed));
104
      ASSERTP(bndptr[i] != -1, ("%d %d %d\n", i, id, ed));
105
      ASSERT(bndind[bndptr[i]] == i);
105
      ASSERT(bndind[bndptr[i]] == i);
106
    }
106
    }
107
  }
107
  }
108
 
108
 
109
  ASSERTP(nbnd == graph->nbnd, ("%d %d\n", nbnd, graph->nbnd));
109
  ASSERTP(nbnd == graph->nbnd, ("%d %d\n", nbnd, graph->nbnd));
110
 
110
 
111
  return 1;
111
  return 1;
112
}
112
}
113
 
113
 
114
/*************************************************************************
114
/*************************************************************************
115
* This function checks whether or not the boundary information is correct
115
* This function checks whether or not the boundary information is correct
116
**************************************************************************/
116
**************************************************************************/
117
int CheckNodeBnd(GraphType *graph, int onbnd) 
117
int CheckNodeBnd(GraphType *graph, int onbnd) 
118
{
118
{
119
  int i, j, nvtxs, nbnd;
119
  int i/* , j */, nvtxs, nbnd;
120
  idxtype *xadj, *adjncy, *where, *bndptr, *bndind;
120
  idxtype *xadj, *adjncy, *where, *bndptr, *bndind;
121
 
121
 
122
  nvtxs = graph->nvtxs;
122
  nvtxs = graph->nvtxs;
123
  xadj = graph->xadj;
123
  xadj = graph->xadj;
124
  adjncy = graph->adjncy;
124
  adjncy = graph->adjncy;
125
  where = graph->where;
125
  where = graph->where;
126
  bndptr = graph->bndptr;
126
  bndptr = graph->bndptr;
127
  bndind = graph->bndind;
127
  bndind = graph->bndind;
128
 
128
 
129
  for (nbnd=0, i=0; i<nvtxs; i++) {
129
  for (nbnd=0, i=0; i<nvtxs; i++) {
130
    if (where[i] == 2) 
130
    if (where[i] == 2) 
131
      nbnd++;   
131
      nbnd++;   
132
  }
132
  }
133
 
133
 
134
  ASSERTP(nbnd == onbnd, ("%d %d\n", nbnd, onbnd));
134
  ASSERTP(nbnd == onbnd, ("%d %d\n", nbnd, onbnd));
135
 
135
 
136
  for (i=0; i<nvtxs; i++) {
136
  for (i=0; i<nvtxs; i++) {
137
    if (where[i] != 2) {
137
    if (where[i] != 2) {
138
      ASSERTP(bndptr[i] == -1, ("%d %d\n", i, bndptr[i]));
138
      ASSERTP(bndptr[i] == -1, ("%d %d\n", i, bndptr[i]));
139
    }
139
    }
140
    else {
140
    else {
141
      ASSERTP(bndptr[i] != -1, ("%d %d\n", i, bndptr[i]));
141
      ASSERTP(bndptr[i] != -1, ("%d %d\n", i, bndptr[i]));
142
    }
142
    }
143
  }
143
  }
144
 
144
 
145
  return 1;
145
  return 1;
146
}
146
}
147
 
147
 
148
 
148
 
149
 
149
 
150
/*************************************************************************
150
/*************************************************************************
151
* This function checks whether or not the rinfo of a vertex is consistent
151
* This function checks whether or not the rinfo of a vertex is consistent
152
**************************************************************************/
152
**************************************************************************/
153
int CheckRInfo(RInfoType *rinfo)
153
int CheckRInfo(RInfoType *rinfo)
154
{
154
{
155
  int i, j;
155
  int i, j;
156
 
156
 
157
  for (i=0; i<rinfo->ndegrees; i++) {
157
  for (i=0; i<rinfo->ndegrees; i++) {
158
    for (j=i+1; j<rinfo->ndegrees; j++)
158
    for (j=i+1; j<rinfo->ndegrees; j++)
159
      ASSERTP(rinfo->edegrees[i].pid != rinfo->edegrees[j].pid, ("%d %d %d %d\n", i, j, rinfo->edegrees[i].pid, rinfo->edegrees[j].pid));
159
      ASSERTP(rinfo->edegrees[i].pid != rinfo->edegrees[j].pid, ("%d %d %d %d\n", i, j, rinfo->edegrees[i].pid, rinfo->edegrees[j].pid));
160
  }
160
  }
161
 
161
 
162
  return 1;
162
  return 1;
163
}
163
}
164
 
164
 
165
 
165
 
166
 
166
 
167
/*************************************************************************
167
/*************************************************************************
168
* This function checks the correctness of the NodeFM data structures
168
* This function checks the correctness of the NodeFM data structures
169
**************************************************************************/
169
**************************************************************************/
170
int CheckNodePartitionParams(GraphType *graph)
170
int CheckNodePartitionParams(GraphType *graph)
171
{
171
{
172
  int i, j, k, l, nvtxs, me, other;
172
  int i, j/* , k, l */, nvtxs, me, other;
173
  idxtype *xadj, *adjncy, *adjwgt, *vwgt, *where;
173
  idxtype *xadj, *adjncy, *adjwgt, *vwgt, *where;
174
  idxtype edegrees[2], pwgts[3];
174
  idxtype edegrees[2], pwgts[3];
175
 
175
 
176
  nvtxs = graph->nvtxs;
176
  nvtxs = graph->nvtxs;
177
  xadj = graph->xadj;
177
  xadj = graph->xadj;
178
  vwgt = graph->vwgt;
178
  vwgt = graph->vwgt;
179
  adjncy = graph->adjncy;
179
  adjncy = graph->adjncy;
180
  adjwgt = graph->adjwgt;
180
  adjwgt = graph->adjwgt;
181
 
181
 
182
  where = graph->where;
182
  where = graph->where;
183
 
183
 
184
  /*------------------------------------------------------------
184
  /*------------------------------------------------------------
185
  / Compute now the separator external degrees
185
  / Compute now the separator external degrees
186
  /------------------------------------------------------------*/
186
  /------------------------------------------------------------*/
187
  pwgts[0] = pwgts[1] = pwgts[2] = 0;
187
  pwgts[0] = pwgts[1] = pwgts[2] = 0;
188
  for (i=0; i<nvtxs; i++) {
188
  for (i=0; i<nvtxs; i++) {
189
    me = where[i];
189
    me = where[i];
190
    pwgts[me] += vwgt[i];
190
    pwgts[me] += vwgt[i];
191
 
191
 
192
    if (me == 2) { /* If it is on the separator do some computations */
192
    if (me == 2) { /* If it is on the separator do some computations */
193
      edegrees[0] = edegrees[1] = 0;
193
      edegrees[0] = edegrees[1] = 0;
194
 
194
 
195
      for (j=xadj[i]; j<xadj[i+1]; j++) {
195
      for (j=xadj[i]; j<xadj[i+1]; j++) {
196
        other = where[adjncy[j]];
196
        other = where[adjncy[j]];
197
        if (other != 2)
197
        if (other != 2)
198
          edegrees[other] += vwgt[adjncy[j]];
198
          edegrees[other] += vwgt[adjncy[j]];
199
      }
199
      }
200
      if (edegrees[0] != graph->nrinfo[i].edegrees[0] || edegrees[1] != graph->nrinfo[i].edegrees[1]) {
200
      if (edegrees[0] != graph->nrinfo[i].edegrees[0] || edegrees[1] != graph->nrinfo[i].edegrees[1]) {
201
        printf("Something wrong with edegrees: %d %d %d %d %d\n", i, edegrees[0], edegrees[1], graph->nrinfo[i].edegrees[0], graph->nrinfo[i].edegrees[1]);
201
        printf("Something wrong with edegrees: %d %d %d %d %d\n", i, edegrees[0], edegrees[1], graph->nrinfo[i].edegrees[0], graph->nrinfo[i].edegrees[1]);
202
        return 0;
202
        return 0;
203
      }
203
      }
204
    }
204
    }
205
  }
205
  }
206
 
206
 
207
  if (pwgts[0] != graph->pwgts[0] || pwgts[1] != graph->pwgts[1] || pwgts[2] != graph->pwgts[2])
207
  if (pwgts[0] != graph->pwgts[0] || pwgts[1] != graph->pwgts[1] || pwgts[2] != graph->pwgts[2])
208
    printf("Something wrong with part-weights: %d %d %d %d %d %d\n", pwgts[0], pwgts[1], pwgts[2], graph->pwgts[0], graph->pwgts[1], graph->pwgts[2]);
208
    printf("Something wrong with part-weights: %d %d %d %d %d %d\n", pwgts[0], pwgts[1], pwgts[2], graph->pwgts[0], graph->pwgts[1], graph->pwgts[2]);
209
 
209
 
210
  return 1;
210
  return 1;
211
}
211
}
212
 
212
 
213
 
213
 
214
/*************************************************************************
214
/*************************************************************************
215
* This function checks if the separator is indeed a separator
215
* This function checks if the separator is indeed a separator
216
**************************************************************************/
216
**************************************************************************/
217
int IsSeparable(GraphType *graph)
217
int IsSeparable(GraphType *graph)
218
{
218
{
219
  int i, j, nvtxs, other;
219
  int i, j, nvtxs, other;
220
  idxtype *xadj, *adjncy, *where;
220
  idxtype *xadj, *adjncy, *where;
221
 
221
 
222
  nvtxs = graph->nvtxs;
222
  nvtxs = graph->nvtxs;
223
  xadj = graph->xadj;
223
  xadj = graph->xadj;
224
  adjncy = graph->adjncy;
224
  adjncy = graph->adjncy;
225
  where = graph->where;
225
  where = graph->where;
226
 
226
 
227
  for (i=0; i<nvtxs; i++) {
227
  for (i=0; i<nvtxs; i++) {
228
    if (where[i] == 2)
228
    if (where[i] == 2)
229
      continue;
229
      continue;
230
    other = (where[i]+1)%2;
230
    other = (where[i]+1)%2;
231
    for (j=xadj[i]; j<xadj[i+1]; j++) {
231
    for (j=xadj[i]; j<xadj[i+1]; j++) {
232
      ASSERTP(where[adjncy[j]] != other, ("%d %d %d %d %d %d\n", i, where[i], adjncy[j], where[adjncy[j]], xadj[i+1]-xadj[i], xadj[adjncy[j]+1]-xadj[adjncy[j]]));
232
      ASSERTP(where[adjncy[j]] != other, ("%d %d %d %d %d %d\n", i, where[i], adjncy[j], where[adjncy[j]], xadj[i+1]-xadj[i], xadj[adjncy[j]+1]-xadj[adjncy[j]]));
233
    }
233
    }
234
  }
234
  }
235
 
235
 
236
  return 1;
236
  return 1;
237
}
237
}
238
 
238
 
239
 
239