1 /* slo.f -- translated by f2c (version of 25 March 1992 12:58:56). */
2
3 #include <../src/mat/graphops/color/impls/minpack/color.h>
4
MINPACKslo(PetscInt * n,const PetscInt * indrow,const PetscInt * jpntr,const PetscInt * indcol,const PetscInt * ipntr,PetscInt * ndeg,PetscInt * list,PetscInt * maxclq,PetscInt * iwa1,PetscInt * iwa2,PetscInt * iwa3,PetscInt * iwa4)5 PetscErrorCode MINPACKslo(PetscInt *n, const PetscInt *indrow, const PetscInt *jpntr, const PetscInt *indcol, const PetscInt *ipntr, PetscInt *ndeg, PetscInt *list, PetscInt *maxclq, PetscInt *iwa1, PetscInt *iwa2, PetscInt *iwa3, PetscInt *iwa4)
6 {
7 /* System generated locals */
8 PetscInt i__1, i__2, i__3, i__4;
9
10 /* Local variables */
11 PetscInt jcol, ic, ip, jp, ir, mindeg, numdeg, numord;
12
13 /* Given the sparsity pattern of an m by n matrix A, this */
14 /* subroutine determines the smallest-last ordering of the */
15 /* columns of A. */
16 /* The smallest-last ordering is defined for the loopless */
17 /* graph G with vertices a(j), j = 1,2,...,n where a(j) is the */
18 /* j-th column of A and with edge (a(i),a(j)) if and only if */
19 /* columns i and j have a non-zero in the same row position. */
20 /* The smallest-last ordering is determined recursively by */
21 /* letting list(k), k = n,...,1 be a column with least degree */
22 /* in the subgraph spanned by the un-ordered columns. */
23 /* Note that the value of m is not needed by slo and is */
24 /* therefore not present in the subroutine statement. */
25 /* The subroutine statement is */
26 /* subroutine slo(n,indrow,jpntr,indcol,ipntr,ndeg,list, */
27 /* maxclq,iwa1,iwa2,iwa3,iwa4) */
28 /* where */
29 /* n is a positive integer input variable set to the number */
30 /* of columns of A. */
31 /* indrow is an integer input array which contains the row */
32 /* indices for the non-zeroes in the matrix A. */
33 /* jpntr is an integer input array of length n + 1 which */
34 /* specifies the locations of the row indices in indrow. */
35 /* The row indices for column j are */
36 /* indrow(k), k = jpntr(j),...,jpntr(j+1)-1. */
37 /* Note that jpntr(n+1)-1 is then the number of non-zero */
38 /* elements of the matrix A. */
39 /* indcol is an integer input array which contains the */
40 /* column indices for the non-zeroes in the matrix A. */
41 /* ipntr is an integer input array of length m + 1 which */
42 /* specifies the locations of the column indices in indcol. */
43 /* The column indices for row i are */
44 /* indcol(k), k = ipntr(i),...,ipntr(i+1)-1. */
45 /* Note that ipntr(m+1)-1 is then the number of non-zero */
46 /* elements of the matrix A. */
47 /* ndeg is an integer input array of length n which specifies */
48 /* the degree sequence. The degree of the j-th column */
49 /* of A is ndeg(j). */
50 /* list is an integer output array of length n which specifies */
51 /* the smallest-last ordering of the columns of A. The j-th */
52 /* column in this order is list(j). */
53 /* maxclq is an integer output variable set to the size */
54 /* of the largest clique found during the ordering. */
55 /* iwa1,iwa2,iwa3, and iwa4 are integer work arrays of length n. */
56 /* Subprograms called */
57 /* FORTRAN-supplied ... min */
58 /* Argonne National Laboratory. MINPACK Project. August 1984. */
59 /* Thomas F. Coleman, Burton S. Garbow, Jorge J. More' */
60
61 PetscFunctionBegin;
62 /* Parameter adjustments */
63 --iwa4;
64 --iwa3;
65 --iwa2;
66 --list;
67 --ndeg;
68 --ipntr;
69 --indcol;
70 --jpntr;
71 --indrow;
72
73 /* Function Body */
74 mindeg = *n;
75 i__1 = *n;
76 for (jp = 1; jp <= i__1; ++jp) {
77 iwa1[jp - 1] = 0;
78 iwa4[jp] = *n;
79 list[jp] = ndeg[jp];
80 /* Computing MIN */
81 i__2 = mindeg;
82 i__3 = ndeg[jp];
83 mindeg = PetscMin(i__2, i__3);
84 }
85
86 /* Create a doubly-linked list to access the degrees of the */
87 /* columns. The pointers for the linked list are as follows. */
88
89 /* Each un-ordered column ic is in a list (the degree list) */
90 /* of columns with the same degree. */
91
92 /* iwa1(numdeg) is the first column in the numdeg list */
93 /* unless iwa1(numdeg) = 0. In this case there are */
94 /* no columns in the numdeg list. */
95
96 /* iwa2(ic) is the column before ic in the degree list */
97 /* unless iwa2(ic) = 0. In this case ic is the first */
98 /* column in this degree list. */
99
100 /* iwa3(ic) is the column after ic in the degree list */
101 /* unless iwa3(ic) = 0. In this case ic is the last */
102 /* column in this degree list. */
103
104 /* If ic is an un-ordered column, then list(ic) is the */
105 /* degree of ic in the graph induced by the un-ordered */
106 /* columns. If jcol is an ordered column, then list(jcol) */
107 /* is the smallest-last order of column jcol. */
108
109 i__1 = *n;
110 for (jp = 1; jp <= i__1; ++jp) {
111 numdeg = ndeg[jp];
112 iwa2[jp] = 0;
113 iwa3[jp] = iwa1[numdeg];
114 if (iwa1[numdeg] > 0) iwa2[iwa1[numdeg]] = jp;
115 iwa1[numdeg] = jp;
116 }
117 *maxclq = 0;
118 numord = *n;
119
120 /* Beginning of iteration loop. */
121
122 L30:
123
124 /* Choose a column jcol of minimal degree mindeg. */
125
126 L40:
127 jcol = iwa1[mindeg];
128 if (jcol > 0) goto L50;
129 ++mindeg;
130 goto L40;
131 L50:
132 list[jcol] = numord;
133
134 /* Mark the size of the largest clique */
135 /* found during the ordering. */
136
137 if (mindeg + 1 == numord && !*maxclq) *maxclq = numord;
138
139 /* Termination test. */
140
141 --numord;
142 if (!numord) goto L80;
143
144 /* Delete column jcol from the mindeg list. */
145
146 iwa1[mindeg] = iwa3[jcol];
147 if (iwa3[jcol] > 0) iwa2[iwa3[jcol]] = 0;
148
149 /* Find all columns adjacent to column jcol. */
150
151 iwa4[jcol] = 0;
152
153 /* Determine all positions (ir,jcol) which correspond */
154 /* to non-zeroes in the matrix. */
155
156 i__1 = jpntr[jcol + 1] - 1;
157 for (jp = jpntr[jcol]; jp <= i__1; ++jp) {
158 ir = indrow[jp];
159
160 /* For each row ir, determine all positions (ir,ic) */
161 /* which correspond to non-zeroes in the matrix. */
162
163 i__2 = ipntr[ir + 1] - 1;
164 for (ip = ipntr[ir]; ip <= i__2; ++ip) {
165 ic = indcol[ip];
166
167 /* Array iwa4 marks columns which are adjacent to */
168 /* column jcol. */
169
170 if (iwa4[ic] > numord) {
171 iwa4[ic] = numord;
172
173 /* Update the pointers to the current degree lists. */
174
175 numdeg = list[ic];
176 --list[ic];
177 /* Computing MIN */
178 i__3 = mindeg;
179 i__4 = list[ic];
180 mindeg = PetscMin(i__3, i__4);
181
182 /* Delete column ic from the numdeg list. */
183
184 if (!iwa2[ic]) iwa1[numdeg] = iwa3[ic];
185 else iwa3[iwa2[ic]] = iwa3[ic];
186
187 if (iwa3[ic] > 0) iwa2[iwa3[ic]] = iwa2[ic];
188
189 /* Add column ic to the numdeg-1 list. */
190
191 iwa2[ic] = 0;
192 iwa3[ic] = iwa1[numdeg - 1];
193 if (iwa1[numdeg - 1] > 0) iwa2[iwa1[numdeg - 1]] = ic;
194 iwa1[numdeg - 1] = ic;
195 }
196 }
197 }
198
199 /* End of iteration loop. */
200
201 goto L30;
202 L80:
203
204 /* Invert the array list. */
205
206 i__1 = *n;
207 for (jcol = 1; jcol <= i__1; ++jcol) iwa2[list[jcol]] = jcol;
208
209 i__1 = *n;
210 for (jp = 1; jp <= i__1; ++jp) list[jp] = iwa2[jp];
211 PetscFunctionReturn(PETSC_SUCCESS);
212 }
213