Debian Codegraph @

packages/seacas/libraries/chaco/klspiff/make_kl_list.c

raw
1 /*
2 * Copyright(C) 1999-2020, 2023 National Technology & Engineering Solutions
3 * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
4 * NTESS, the U.S. Government retains certain rights in this software.
5 *
6 * See packages/seacas/LICENSE for details
7 */
8
9 #include "structs.h" // for bilist, vtx_data
10 #include <stdio.h> // for NULL
11
12 int make_kl_list(struct vtx_data **graph, /* data structure for graph */
13 struct bilist *movelist, /* list of vtxs to be moved */
14 struct bilist ****buckets, /* array of lists for bucket sort */
15 struct bilist **listspace, /* list data structure for each vertex */
16 int *sets, /* processor each vertex is assigned to */
17 int nsets, /* number of sets divided into */
18 int *bspace, /* list of active vertices for bucketsort */
19 int **dvals, /* d-values for each transition */
20 int maxdval /* maximum d-value for a vertex */
21 )
22 {
23 struct bilist **list; /* bucket to erase element from */
24 struct bilist *vptr; /* loops through movelist */
25 int *bptr; /* loops through bspace */
26 int *iptr; /* loops through edge list */
27 int vtx; /* vertex that was moved */
28 int neighbor; /* neighbor of a vertex */
29 int myset; /* set a vertex is in */
30 int newset; /* loops through other sets */
31 int list_length; /* number of values put in bspace */
32 int size; /* array spacing */
33 int i, l; /* loop counter */
34
35 /* First push all the moved vertices onto list, so they can be flagged. */
36 /* They've already been removed from buckets, so want to avoid them. */
37 size = (int)(&(listspace[0][1]) - &(listspace[0][0]));
38 vptr = movelist;
39 bptr = bspace;
40 list_length = 0;
41 while (vptr != NULL) {
42 vtx = ((int)(vptr - listspace[0])) / size;
43 *bptr++ = vtx;
44 if (sets[vtx] >= 0) {
45 sets[vtx] = -sets[vtx] - 1;
46 }
47 ++list_length;
48 vptr = vptr->next;
49 }
50
51 /* Now look at all the neighbors of moved vertices. */
52 vptr = movelist;
53 while (vptr != NULL) {
54 vtx = ((int)(vptr - listspace[0])) / size;
55
56 iptr = graph[vtx]->edges;
57 for (i = graph[vtx]->nedges - 1; i; i--) {
58 neighbor = *(++iptr);
59 if (sets[neighbor] >= 0) {
60 *bptr++ = neighbor;
61 ++list_length;
62 myset = sets[neighbor];
63 sets[neighbor] = -sets[neighbor] - 1;
64
65 /* Remove neighbor entry from all his buckets. */
66 /* Note: vertices in movelist already removed from buckets. */
67 l = 0;
68 for (newset = 0; newset < nsets; newset++) {
69 if (newset != myset) {
70 list = &buckets[myset][newset][dvals[neighbor][l] + maxdval];
71 removebilist(&listspace[l][neighbor], list);
72 l++;
73 }
74 }
75 }
76 }
77 vptr = vptr->next;
78 }
79
80 /* Now that list is constructed, go reconstruct all the set numbers. */
81 bptr = bspace;
82 for (i = list_length; i; i--) {
83 vtx = *bptr++;
84 sets[vtx] = -sets[vtx] - 1;
85 }
86
87 return (list_length);
88 }