Actual source code: slo.c

petsc-3.3-p7 2013-05-11
  2: /* slo.f -- translated by f2c (version of 25 March 1992  12:58:56).*/

  4: #include <../src/mat/color/color.h>

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

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

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

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

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

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

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

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

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

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

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

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

125:     /*     Beginning of iteration loop. */

127: L30:

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

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

141:     /*        Mark the size of the largest clique */
142:     /*        found during the ordering. */

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

148:     /*        Termination test. */

150:     --numord;
151:     if (!numord) {
152:         goto L80;
153:     }

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

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

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

164:     iwa4[jcol] = 0;

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

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

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

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

180:             /*              Array iwa4 marks columns which are adjacent to */
181:             /*              column jcol. */

183:             if (iwa4[ic] > numord) {
184:                 iwa4[ic] = numord;

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

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

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

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

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

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

217:     /*        End of iteration loop. */

219:     goto L30;
220: L80:

222:     /*     Invert the array list. */

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