Actual source code: slo.c

petsc-3.4.5 2014-06-29
  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,const PetscInt * indrow,const PetscInt * jpntr,const PetscInt * indcol,const 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) goto L50;
134:   ++mindeg;
135:   goto L40;
136: L50:
137:   list[jcol] = numord;

139:   /*        Mark the size of the largest clique */
140:   /*        found during the ordering. */

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

144:   /*        Termination test. */

146:   --numord;
147:   if (!numord) goto L80;

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

151:   iwa1[mindeg] = iwa3[jcol];
152:   if (iwa3[jcol] > 0) iwa2[iwa3[jcol]] = 0;

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

156:   iwa4[jcol] = 0;

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

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

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

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

172:       /*              Array iwa4 marks columns which are adjacent to */
173:       /*              column jcol. */

175:       if (iwa4[ic] > numord) {
176:         iwa4[ic] = numord;

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

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

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

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

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

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

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

203:   /*        End of iteration loop. */

205:   goto L30;
206: L80:

208:   /*     Invert the array list. */

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

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