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,
  7:                           PetscInt * maxclq,PetscInt *iwa1,PetscInt * iwa2,PetscInt * iwa3,PetscInt * iwa4)
  8: {
  9:   /* System generated locals */
 10:   PetscInt i__1, i__2, i__3, i__4;

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

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

 63:   /* Parameter adjustments */
 64:   --iwa4;
 65:   --iwa3;
 66:   --iwa2;
 67:   --list;
 68:   --ndeg;
 69:   --ipntr;
 70:   --indcol;
 71:   --jpntr;
 72:   --indrow;

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

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

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

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

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

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

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

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

123:   /*     Beginning of iteration loop. */

125: L30:

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

129: L40:
130:   jcol = iwa1[mindeg];
131:   if (jcol > 0) goto L50;
132:   ++mindeg;
133:   goto L40;
134: L50:
135:   list[jcol] = numord;

137:   /*        Mark the size of the largest clique */
138:   /*        found during the ordering. */

140:   if (mindeg + 1 == numord && !*maxclq) *maxclq = numord;

142:   /*        Termination test. */

144:   --numord;
145:   if (!numord) goto L80;

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

149:   iwa1[mindeg] = iwa3[jcol];
150:   if (iwa3[jcol] > 0) iwa2[iwa3[jcol]] = 0;

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

154:   iwa4[jcol] = 0;

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

159:   i__1 = jpntr[jcol + 1] - 1;
160:   for (jp = jpntr[jcol]; jp <= i__1; ++jp) {
161:     ir = indrow[jp];

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

166:     i__2 = ipntr[ir + 1] - 1;
167:     for (ip = ipntr[ir]; ip <= i__2; ++ip) {
168:       ic = indcol[ip];

170:       /*              Array iwa4 marks columns which are adjacent to */
171:       /*              column jcol. */

173:       if (iwa4[ic] > numord) {
174:         iwa4[ic] = numord;

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

178:         numdeg = list[ic];
179:         --list[ic];
180:         /* Computing MIN */
181:         i__3   = mindeg;
182:         i__4   = list[ic];
183:         mindeg = PetscMin(i__3,i__4);

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

187:         if (!iwa2[ic]) iwa1[numdeg] = iwa3[ic];
188:         else iwa3[iwa2[ic]] = iwa3[ic];

190:         if (iwa3[ic] > 0) iwa2[iwa3[ic]] = iwa2[ic];

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

194:         iwa2[ic] = 0;
195:         iwa3[ic] = iwa1[numdeg - 1];
196:         if (iwa1[numdeg - 1] > 0) iwa2[iwa1[numdeg - 1]] = ic;
197:         iwa1[numdeg - 1] = ic;
198:       }
199:     }
200:   }

202:   /*        End of iteration loop. */

204:   goto L30;
205: L80:

207:   /*     Invert the array list. */

209:   i__1 = *n;
210:   for (jcol = 1; jcol <= i__1; ++jcol) iwa2[list[jcol]] = jcol;

212:   i__1 = *n;
213:   for (jp = 1; jp <= i__1; ++jp) list[jp] = iwa2[jp];
214:   return 0;
215: }