Actual source code: slo.c

petsc-3.9.4 2018-09-11
Report Typos and Errors

  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' */

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

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

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

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

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

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

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

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

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

124:   /*     Beginning of iteration loop. */

126: L30:

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

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

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

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

143:   /*        Termination test. */

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

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

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

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

155:   iwa4[jcol] = 0;

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

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

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

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

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

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

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

179:         numdeg = list[ic];
180:         --list[ic];
181:         /* Computing MIN */
182:         i__3   = mindeg;
183:         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: }