Actual source code: slo.c

  1: #define PETSCMAT_DLL

  3: /* slo.f -- translated by f2c (version of 25 March 1992  12:58:56).*/

 5:  #include petsc.h
 6:  #include src/mat/color/color.h

 10: PetscErrorCode MINPACKslo(PetscInt *n,PetscInt * indrow,PetscInt * jpntr,PetscInt * indcol, PetscInt *ipntr, PetscInt *ndeg,PetscInt * list,
 11:                           PetscInt * maxclq,PetscInt *iwa1,PetscInt * iwa2,PetscInt * iwa3,PetscInt * iwa4)
 12: {
 13:     /* System generated locals */
 14:     PetscInt i__1, i__2, i__3, i__4;

 16:     /* Local variables */
 17:     PetscInt jcol, ic, ip, jp, ir, mindeg, numdeg, numord;

 19: /*     Given the sparsity pattern of an m by n matrix A, this */
 20: /*     subroutine determines the smallest-last ordering of the */
 21: /*     columns of A. */
 22: /*     The smallest-last ordering is defined for the loopless */
 23: /*     graph G with vertices a(j), j = 1,2,...,n where a(j) is the */
 24: /*     j-th column of A and with edge (a(i),a(j)) if and only if */
 25: /*     columns i and j have a non-zero in the same row position. */
 26: /*     The smallest-last ordering is determined recursively by */
 27: /*     letting list(k), k = n,...,1 be a column with least degree */
 28: /*     in the subgraph spanned by the un-ordered columns. */
 29: /*     Note that the value of m is not needed by slo and is */
 30: /*     therefore not present in the subroutine statement. */
 31: /*     The subroutine statement is */
 32: /*       subroutine slo(n,indrow,jpntr,indcol,ipntr,ndeg,list, */
 33: /*                      maxclq,iwa1,iwa2,iwa3,iwa4) */
 34: /*     where */
 35: /*       n is a positive integer input variable set to the number */
 36: /*         of columns of A. */
 37: /*       indrow is an integer input array which contains the row */
 38: /*         indices for the non-zeroes in the matrix A. */
 39: /*       jpntr is an integer input array of length n + 1 which */
 40: /*         specifies the locations of the row indices in indrow. */
 41: /*         The row indices for column j are */
 42: /*               indrow(k), k = jpntr(j),...,jpntr(j+1)-1. */
 43: /*         Note that jpntr(n+1)-1 is then the number of non-zero */
 44: /*         elements of the matrix A. */
 45: /*       indcol is an integer input array which contains the */
 46: /*         column indices for the non-zeroes in the matrix A. */
 47: /*       ipntr is an integer input array of length m + 1 which */
 48: /*         specifies the locations of the column indices in indcol. */
 49: /*         The column indices for row i are */
 50: /*               indcol(k), k = ipntr(i),...,ipntr(i+1)-1. */
 51: /*         Note that ipntr(m+1)-1 is then the number of non-zero */
 52: /*         elements of the matrix A. */
 53: /*       ndeg is an integer input array of length n which specifies */
 54: /*         the degree sequence. The degree of the j-th column */
 55: /*         of A is ndeg(j). */
 56: /*       list is an integer output array of length n which specifies */
 57: /*         the smallest-last ordering of the columns of A. The j-th */
 58: /*         column in this order is list(j). */
 59: /*       maxclq is an integer output variable set to the size */
 60: /*         of the largest clique found during the ordering. */
 61: /*       iwa1,iwa2,iwa3, and iwa4 are integer work arrays of length n. */
 62: /*     Subprograms called */
 63: /*       FORTRAN-supplied ... min */
 64: /*     Argonne National Laboratory. MINPACK Project. August 1984. */
 65: /*     Thomas F. Coleman, Burton S. Garbow, Jorge J. More' */

 68:     /* Parameter adjustments */
 69:     --iwa4;
 70:     --iwa3;
 71:     --iwa2;
 72:     --list;
 73:     --ndeg;
 74:     --ipntr;
 75:     --indcol;
 76:     --jpntr;
 77:     --indrow;

 79:     /* Function Body */
 80:     mindeg = *n;
 81:     i__1 = *n;
 82:     for (jp = 1; jp <= i__1; ++jp) {
 83:         iwa1[jp - 1] = 0;
 84:         iwa4[jp] = *n;
 85:         list[jp] = ndeg[jp];
 86:         /* Computing MIN */
 87:         i__2 = mindeg, i__3 = ndeg[jp];
 88:         mindeg = PetscMin(i__2,i__3);
 89:     }

 91:     /*     Create a doubly-linked list to access the degrees of the */
 92:     /*     columns. The pointers for the linked list are as follows. */

 94:     /*     Each un-ordered column ic is in a list (the degree list) */
 95:     /*     of columns with the same degree. */

 97:     /*     iwa1(numdeg) is the first column in the numdeg list */
 98:     /*     unless iwa1(numdeg) = 0. In this case there are */
 99:     /*     no columns in the numdeg list. */

101:     /*     iwa2(ic) is the column before ic in the degree list */
102:     /*     unless iwa2(ic) = 0. In this case ic is the first */
103:     /*     column in this degree list. */

105:     /*     iwa3(ic) is the column after ic in the degree list */
106:     /*     unless iwa3(ic) = 0. In this case ic is the last */
107:     /*     column in this degree list. */

109:     /*     If ic is an un-ordered column, then list(ic) is the */
110:     /*     degree of ic in the graph induced by the un-ordered */
111:     /*     columns. If jcol is an ordered column, then list(jcol) */
112:     /*     is the smallest-last order of column jcol. */

114:     i__1 = *n;
115:     for (jp = 1; jp <= i__1; ++jp) {
116:         numdeg = ndeg[jp];
117:         iwa2[jp] = 0;
118:         iwa3[jp] = iwa1[numdeg];
119:         if (iwa1[numdeg] > 0) {
120:             iwa2[iwa1[numdeg]] = jp;
121:         }
122:         iwa1[numdeg] = jp;
123:     }
124:     *maxclq = 0;
125:     numord = *n;

127:     /*     Beginning of iteration loop. */

129: L30:

131:     /*        Choose a column jcol of minimal degree mindeg. */

133: L40:
134:     jcol = iwa1[mindeg];
135:     if (jcol > 0) {
136:         goto L50;
137:     }
138:     ++mindeg;
139:     goto L40;
140: L50:
141:     list[jcol] = numord;

143:     /*        Mark the size of the largest clique */
144:     /*        found during the ordering. */

146:     if (mindeg + 1 == numord && !*maxclq) {
147:         *maxclq = numord;
148:     }

150:     /*        Termination test. */

152:     --numord;
153:     if (!numord) {
154:         goto L80;
155:     }

157:     /*        Delete column jcol from the mindeg list. */

159:     iwa1[mindeg] = iwa3[jcol];
160:     if (iwa3[jcol] > 0) {
161:         iwa2[iwa3[jcol]] = 0;
162:     }

164:     /*        Find all columns adjacent to column jcol. */

166:     iwa4[jcol] = 0;

168:     /*        Determine all positions (ir,jcol) which correspond */
169:     /*        to non-zeroes in the matrix. */

171:     i__1 = jpntr[jcol + 1] - 1;
172:     for (jp = jpntr[jcol]; jp <= i__1; ++jp) {
173:         ir = indrow[jp];

175:         /*           For each row ir, determine all positions (ir,ic) */
176:         /*           which correspond to non-zeroes in the matrix. */

178:         i__2 = ipntr[ir + 1] - 1;
179:         for (ip = ipntr[ir]; ip <= i__2; ++ip) {
180:             ic = indcol[ip];

182:             /*              Array iwa4 marks columns which are adjacent to */
183:             /*              column jcol. */

185:             if (iwa4[ic] > numord) {
186:                 iwa4[ic] = numord;

188:                 /*                 Update the pointers to the current degree lists. */

190:                 numdeg = list[ic];
191:                 --list[ic];
192:                 /* Computing MIN */
193:                 i__3 = mindeg, i__4 = list[ic];
194:                 mindeg = PetscMin(i__3,i__4);

196:                 /*                 Delete column ic from the numdeg list. */

198:                 if (!iwa2[ic]) {
199:                     iwa1[numdeg] = iwa3[ic];
200:                 } else {
201:                     iwa3[iwa2[ic]] = iwa3[ic];
202:                 }
203:                 if (iwa3[ic] > 0) {
204:                     iwa2[iwa3[ic]] = iwa2[ic];
205:                 }

207:                 /*                 Add column ic to the numdeg-1 list. */

209:                 iwa2[ic] = 0;
210:                 iwa3[ic] = iwa1[numdeg - 1];
211:                 if (iwa1[numdeg - 1] > 0) {
212:                     iwa2[iwa1[numdeg - 1]] = ic;
213:                 }
214:                 iwa1[numdeg - 1] = ic;
215:             }
216:         }
217:     }

219:     /*        End of iteration loop. */

221:     goto L30;
222: L80:

224:     /*     Invert the array list. */

226:     i__1 = *n;
227:     for (jcol = 1; jcol <= i__1; ++jcol) {
228:         iwa2[list[jcol]] = jcol;
229:     }
230:     i__1 = *n;
231:     for (jp = 1; jp <= i__1; ++jp) {
232:         list[jp] = iwa2[jp];
233:     }
234:     return(0);
235: }