1 /* This software was developed by Bruce Hendrickson and Robert Leland *
2 * at Sandia National Laboratories under US Department of Energy *
3 * contract DE-AC04-76DP00789 and is copyrighted by Sandia Corporation. */
4
5 #include <stdio.h>
6 #include "structs.h"
7 #include "defs.h"
8 #include "internal.h"
9
10
check_internal(graph,nvtxs,int_list,set_list,vtx_elems,total_vwgt,assign,nsets_tot)11 void check_internal(graph, nvtxs, int_list, set_list, vtx_elems,
12 total_vwgt, assign, nsets_tot)
13 struct vtx_data **graph; /* graph data structure */
14 int nvtxs; /* number of vertices in graph */
15 struct bidint *int_list; /* sorted list of internal weights per set */
16 struct bidint *set_list; /* head of vtx_elems lists */
17 struct bidint *vtx_elems; /* start of vertex data */
18 int *total_vwgt; /* total weight in each set */
19 short *assign; /* current assignment */
20 int nsets_tot; /* total number of sets */
21 {
22 struct bidint *ptr, *ptr2; /* elements in int_list */
23 struct bidint *old_ptr, *old_ptr2; /* elements in set_list */
24 int vwgt_sum; /* sum of vertex weights */
25 short set, set2; /* sets two vertices are in */
26 int sum; /* sum of internal weights */
27 int nseen; /* number of vertices found in set_lists */
28 int old_val, val; /* consecutive values in int_list */
29 int vtx; /* vertex in set list */
30 int internal; /* is a vertex internal or not? */
31 int size; /* array spacing */
32 int j, k; /* loop counters */
33
34 k = 0;
35 size = (int) (&(int_list[1]) - &(int_list[0]));
36 nseen = 0;
37 old_val = -1;
38 old_ptr = &(int_list[nsets_tot]);
39 for (ptr = int_list[nsets_tot].next; ptr != NULL; ptr = ptr->next) {
40 set = ((int) (ptr - int_list)) / size;
41 val = ptr->val;
42 if (val < old_val) {
43 printf("int_list out of order, k=%d, set = %d, old_val=%d, val = %d\n",
44 k, set, old_val, val);
45 }
46 if (ptr->prev != old_ptr) {
47 printf(" int_list back link screwed up, set=%d, k=%d, old_ptr=%ld, ptr->prev = %ld\n",
48 set, k, (long) old_ptr, (long) ptr->prev);
49 }
50 old_ptr = ptr;
51 old_val = val;
52
53 vwgt_sum = 0;
54 sum = 0;
55 old_ptr2 = &(set_list[set]);
56 for (ptr2 = set_list[set].next; ptr2 != NULL; ptr2 = ptr2->next) {
57 vtx = ((int) (ptr2 - vtx_elems)) / size;
58 vwgt_sum += graph[vtx]->vwgt;
59 if (ptr2->prev != old_ptr2) {
60 printf(" set_list back link screwed up, set=%d, k=%d, old_ptr2=%ld, ptr2->prev = %ld\n",
61 set, k, (long) old_ptr2, (long) ptr2->prev);
62 }
63 old_ptr2 = ptr2;
64
65 ++nseen;
66 if (assign[vtx] != set) {
67 printf("assign[%d] = %d, but in set_list[%d]\n",
68 vtx, assign[vtx], set);
69 }
70 internal = TRUE;
71 for (j = 1; j < graph[vtx]->nedges && internal; j++) {
72 set2 = assign[graph[vtx]->edges[j]];
73 internal = (set2 == set);
74 }
75 if (internal) {
76 sum += graph[vtx]->vwgt;
77 }
78 }
79 if (sum != val) {
80 printf("set = %d, val = %d, but I compute internal = %d\n",
81 set, val, sum);
82 }
83 if (vwgt_sum != total_vwgt[set]) {
84 printf(" vwgt_sum = %d, but total_vwgt[%d] = %d\n",
85 vwgt_sum, set, total_vwgt[set]);
86 }
87 k++;
88 }
89 if (k != nsets_tot) {
90 printf(" Only %d sets in int_sets list, but nsets_tot = %d\n", k, nsets_tot);
91 }
92 if (nseen != nvtxs) {
93 printf(" Only %d vertices found in int_sets lists, but nvtxs = %d\n", nseen, nvtxs);
94 }
95 }
96