Actual source code: slo.c
2: /* slo.f -- translated by f2c (version of 25 March 1992 12:58:56).*/
4: #include <../src/mat/color/impls/minpack/color.h>
6: 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)
7: {
8: /* System generated locals */
9: PetscInt i__1, i__2, i__3, i__4;
11: /* Local variables */
12: PetscInt jcol, ic, ip, jp, ir, mindeg, numdeg, numord;
14: /* Given the sparsity pattern of an m by n matrix A, this */
15: /* subroutine determines the smallest-last ordering of the */
16: /* columns of A. */
17: /* The smallest-last ordering is defined for the loopless */
18: /* graph G with vertices a(j), j = 1,2,...,n where a(j) is the */
19: /* j-th column of A and with edge (a(i),a(j)) if and only if */
20: /* columns i and j have a non-zero in the same row position. */
21: /* The smallest-last ordering is determined recursively by */
22: /* letting list(k), k = n,...,1 be a column with least degree */
23: /* in the subgraph spanned by the un-ordered columns. */
24: /* Note that the value of m is not needed by slo and is */
25: /* therefore not present in the subroutine statement. */
26: /* The subroutine statement is */
27: /* subroutine slo(n,indrow,jpntr,indcol,ipntr,ndeg,list, */
28: /* maxclq,iwa1,iwa2,iwa3,iwa4) */
29: /* where */
30: /* n is a positive integer input variable set to the number */
31: /* of columns of A. */
32: /* indrow is an integer input array which contains the row */
33: /* indices for the non-zeroes in the matrix A. */
34: /* jpntr is an integer input array of length n + 1 which */
35: /* specifies the locations of the row indices in indrow. */
36: /* The row indices for column j are */
37: /* indrow(k), k = jpntr(j),...,jpntr(j+1)-1. */
38: /* Note that jpntr(n+1)-1 is then the number of non-zero */
39: /* elements of the matrix A. */
40: /* indcol is an integer input array which contains the */
41: /* column indices for the non-zeroes in the matrix A. */
42: /* ipntr is an integer input array of length m + 1 which */
43: /* specifies the locations of the column indices in indcol. */
44: /* The column indices for row i are */
45: /* indcol(k), k = ipntr(i),...,ipntr(i+1)-1. */
46: /* Note that ipntr(m+1)-1 is then the number of non-zero */
47: /* elements of the matrix A. */
48: /* ndeg is an integer input array of length n which specifies */
49: /* the degree sequence. The degree of the j-th column */
50: /* of A is ndeg(j). */
51: /* list is an integer output array of length n which specifies */
52: /* the smallest-last ordering of the columns of A. The j-th */
53: /* column in this order is list(j). */
54: /* maxclq is an integer output variable set to the size */
55: /* of the largest clique found during the ordering. */
56: /* iwa1,iwa2,iwa3, and iwa4 are integer work arrays of length n. */
57: /* Subprograms called */
58: /* FORTRAN-supplied ... min */
59: /* Argonne National Laboratory. MINPACK Project. August 1984. */
60: /* Thomas F. Coleman, Burton S. Garbow, Jorge J. More' */
62: /* Parameter adjustments */
63: --iwa4;
64: --iwa3;
65: --iwa2;
66: --list;
67: --ndeg;
68: --ipntr;
69: --indcol;
70: --jpntr;
71: --indrow;
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: }
86: /* Create a doubly-linked list to access the degrees of the */
87: /* columns. The pointers for the linked list are as follows. */
89: /* Each un-ordered column ic is in a list (the degree list) */
90: /* of columns with the same degree. */
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. */
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. */
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. */
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. */
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;
120: /* Beginning of iteration loop. */
122: L30:
124: /* Choose a column jcol of minimal degree mindeg. */
126: L40:
127: jcol = iwa1[mindeg];
128: if (jcol > 0) goto L50;
129: ++mindeg;
130: goto L40;
131: L50:
132: list[jcol] = numord;
134: /* Mark the size of the largest clique */
135: /* found during the ordering. */
137: if (mindeg + 1 == numord && !*maxclq) *maxclq = numord;
139: /* Termination test. */
141: --numord;
142: if (!numord) goto L80;
144: /* Delete column jcol from the mindeg list. */
146: iwa1[mindeg] = iwa3[jcol];
147: if (iwa3[jcol] > 0) iwa2[iwa3[jcol]] = 0;
149: /* Find all columns adjacent to column jcol. */
151: iwa4[jcol] = 0;
153: /* Determine all positions (ir,jcol) which correspond */
154: /* to non-zeroes in the matrix. */
156: i__1 = jpntr[jcol + 1] - 1;
157: for (jp = jpntr[jcol]; jp <= i__1; ++jp) {
158: ir = indrow[jp];
160: /* For each row ir, determine all positions (ir,ic) */
161: /* which correspond to non-zeroes in the matrix. */
163: i__2 = ipntr[ir + 1] - 1;
164: for (ip = ipntr[ir]; ip <= i__2; ++ip) {
165: ic = indcol[ip];
167: /* Array iwa4 marks columns which are adjacent to */
168: /* column jcol. */
170: if (iwa4[ic] > numord) {
171: iwa4[ic] = numord;
173: /* Update the pointers to the current degree lists. */
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);
182: /* Delete column ic from the numdeg list. */
184: if (!iwa2[ic]) iwa1[numdeg] = iwa3[ic];
185: else iwa3[iwa2[ic]] = iwa3[ic];
187: if (iwa3[ic] > 0) iwa2[iwa3[ic]] = iwa2[ic];
189: /* Add column ic to the numdeg-1 list. */
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: }
199: /* End of iteration loop. */
201: goto L30;
202: L80:
204: /* Invert the array list. */
206: i__1 = *n;
207: for (jcol = 1; jcol <= i__1; ++jcol) iwa2[list[jcol]] = jcol;
209: i__1 = *n;
210: for (jp = 1; jp <= i__1; ++jp) list[jp] = iwa2[jp];
211: return 0;
212: }