Actual source code: ido.c

  1: #define PETSCMAT_DLL
  2: /* ido.f -- translated by f2c (version of 25 March 1992  12:58:56).*/

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

  6: static PetscInt c_n1 = -1;

 10: PetscErrorCode MINPACKido(PetscInt *m,PetscInt * n,PetscInt * indrow,PetscInt * jpntr,PetscInt * indcol,PetscInt * ipntr,PetscInt * ndeg,
 11:                PetscInt *list,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 = 0, ncomp = 0, ic, ip, jp, ir, maxinc, numinc, numord, maxlst, numwgt, numlst;

 19: /*     Given the sparsity pattern of an m by n matrix A, this */
 20: /*     subroutine determines an incidence-degree ordering of the */
 21: /*     columns of A. */
 22: /*     The incidence-degree 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 incidence-degree ordering is determined recursively by */
 27: /*     letting list(k), k = 1,...,n be a column with maximal */
 28: /*     incidence to the subgraph spanned by the ordered columns. */
 29: /*     Among all the columns of maximal incidence, ido chooses a */
 30: /*     column of maximal degree. */
 31: /*     The subroutine statement is */
 32: /*       subroutine ido(m,n,indrow,jpntr,indcol,ipntr,ndeg,list, */
 33: /*                      maxclq,iwa1,iwa2,iwa3,iwa4) */
 34: /*     where */
 35: /*       m is a positive integer input variable set to the number */
 36: /*         of rows of A. */
 37: /*       n is a positive integer input variable set to the number */
 38: /*         of columns of A. */
 39: /*       indrow is an integer input array which contains the row */
 40: /*         indices for the non-zeroes in the matrix A. */
 41: /*       jpntr is an integer input array of length n + 1 which */
 42: /*         specifies the locations of the row indices in indrow. */
 43: /*         The row indices for column j are */
 44: /*               indrow(k), k = jpntr(j),...,jpntr(j+1)-1. */
 45: /*         Note that jpntr(n+1)-1 is then the number of non-zero */
 46: /*         elements of the matrix A. */
 47: /*       indcol is an integer input array which contains the */
 48: /*         column indices for the non-zeroes in the matrix A. */
 49: /*       ipntr is an integer input array of length m + 1 which */
 50: /*         specifies the locations of the column indices in indcol. */
 51: /*         The column indices for row i are */
 52: /*               indcol(k), k = ipntr(i),...,ipntr(i+1)-1. */
 53: /*         Note that ipntr(m+1)-1 is then the number of non-zero */
 54: /*         elements of the matrix A. */
 55: /*       ndeg is an integer input array of length n which specifies */
 56: /*         the degree sequence. The degree of the j-th column */
 57: /*         of A is ndeg(j). */
 58: /*       list is an integer output array of length n which specifies */
 59: /*         the incidence-degree ordering of the columns of A. The j-th */
 60: /*         column in this order is list(j). */
 61: /*       maxclq is an integer output variable set to the size */
 62: /*         of the largest clique found during the ordering. */
 63: /*       iwa1,iwa2,iwa3, and iwa4 are integer work arrays of length n. */
 64: /*     Subprograms called */
 65: /*       MINPACK-supplied ... numsrt */
 66: /*       FORTRAN-supplied ... max */
 67: /*     Argonne National Laboratory. MINPACK Project. August 1984. */
 68: /*     Thomas F. Coleman, Burton S. Garbow, Jorge J. More' */

 70: /*     Sort the degree sequence. */

 73:     /* Parameter adjustments */
 74:     --iwa4;
 75:     --iwa3;
 76:     --iwa2;
 77:     --list;
 78:     --ndeg;
 79:     --ipntr;
 80:     --indcol;
 81:     --jpntr;
 82:     --indrow;

 84:     /* Function Body */
 85:     i__1 = *n - 1;
 86:     MINPACKnumsrt(n, &i__1, &ndeg[1], &c_n1, &iwa4[1], &iwa2[1], &iwa3[1]);

 88: /*     Initialization block. */
 89: /*     Create a doubly-linked list to access the incidences of the */
 90: /*     columns. The pointers for the linked list are as follows. */
 91: /*     Each un-ordered column ic is in a list (the incidence list) */
 92: /*     of columns with the same incidence. */
 93: /*     iwa1(numinc) is the first column in the numinc list */
 94: /*     unless iwa1(numinc) = 0. In this case there are */
 95: /*     no columns in the numinc list. */
 96: /*     iwa2(ic) is the column before ic in the incidence list */
 97: /*     unless iwa2(ic) = 0. In this case ic is the first */
 98: /*     column in this incidence list. */
 99: /*     iwa3(ic) is the column after ic in the incidence list */
100: /*     unless iwa3(ic) = 0. In this case ic is the last */
101: /*     column in this incidence list. */
102: /*     If ic is an un-ordered column, then list(ic) is the */
103: /*     incidence of ic to the graph induced by the ordered */
104: /*     columns. If jcol is an ordered column, then list(jcol) */
105: /*     is the incidence-degree order of column jcol. */

107:     maxinc = 0;
108:     for (jp = *n; jp >= 1; --jp) {
109:         ic = iwa4[jp];
110:         iwa1[*n - jp] = 0;
111:         iwa2[ic] = 0;
112:         iwa3[ic] = iwa1[0];
113:         if (iwa1[0] > 0) {
114:             iwa2[iwa1[0]] = ic;
115:         }
116:         iwa1[0] = ic;
117:         iwa4[jp] = 0;
118:         list[jp] = 0;
119:     }

121: /*     Determine the maximal search length for the list */
122: /*     of columns of maximal incidence. */

124:     maxlst = 0;
125:     i__1 = *m;
126:     for (ir = 1; ir <= i__1; ++ir) {
127: /* Computing 2nd power */
128:         i__2 = ipntr[ir + 1] - ipntr[ir];
129:         maxlst += i__2 * i__2;
130:     }
131:     maxlst /= *n;
132:     *maxclq = 0;
133:     numord = 1;

135: /*     Beginning of iteration loop. */

137: L30:

139: /*        Choose a column jcol of maximal degree among the */
140: /*        columns of maximal incidence maxinc. */

142: L40:
143:     jp = iwa1[maxinc];
144:     if (jp > 0) {
145:         goto L50;
146:     }
147:     --maxinc;
148:     goto L40;
149: L50:
150:     numwgt = -1;
151:     i__1 = maxlst;
152:     for (numlst = 1; numlst <= i__1; ++numlst) {
153:         if (ndeg[jp] > numwgt) {
154:             numwgt = ndeg[jp];
155:             jcol = jp;
156:         }
157:         jp = iwa3[jp];
158:         if (jp <= 0) {
159:             goto L70;
160:         }
161:     }
162: L70:
163:     list[jcol] = numord;

165: /*        Update the size of the largest clique */
166: /*        found during the ordering. */

168:     if (!maxinc) {
169:         ncomp = 0;
170:     }
171:     ++ncomp;
172:     if (maxinc + 1 == ncomp) {
173:         *maxclq = PetscMax(*maxclq,ncomp);
174:     }

176: /*        Termination test. */

178:     ++numord;
179:     if (numord > *n) {
180:         goto L100;
181:     }

183: /*        Delete column jcol from the maxinc list. */

185:     if (!iwa2[jcol]) {
186:         iwa1[maxinc] = iwa3[jcol];
187:     } else {
188:         iwa3[iwa2[jcol]] = iwa3[jcol];
189:     }
190:     if (iwa3[jcol] > 0) {
191:         iwa2[iwa3[jcol]] = iwa2[jcol];
192:     }

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

196:     iwa4[jcol] = *n;

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

201:     i__1 = jpntr[jcol + 1] - 1;
202:     for (jp = jpntr[jcol]; jp <= i__1; ++jp) {
203:         ir = indrow[jp];

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

208:         i__2 = ipntr[ir + 1] - 1;
209:         for (ip = ipntr[ir]; ip <= i__2; ++ip) {
210:             ic = indcol[ip];

212: /*              Array iwa4 marks columns which are adjacent to */
213: /*              column jcol. */

215:             if (iwa4[ic] < numord) {
216:                 iwa4[ic] = numord;

218: /*                 Update the pointers to the current incidence lists. */

220:                 numinc = list[ic];
221:                 ++list[ic];
222: /* Computing MAX */
223:                 i__3 = maxinc, i__4 = list[ic];
224:                 maxinc = PetscMax(i__3,i__4);

226: /*                 Delete column ic from the numinc list. */

228:                 if (!iwa2[ic]) {
229:                     iwa1[numinc] = iwa3[ic];
230:                 } else {
231:                     iwa3[iwa2[ic]] = iwa3[ic];
232:                 }
233:                 if (iwa3[ic] > 0) {
234:                     iwa2[iwa3[ic]] = iwa2[ic];
235:                 }

237: /*                 Add column ic to the numinc+1 list. */

239:                 iwa2[ic] = 0;
240:                 iwa3[ic] = iwa1[numinc + 1];
241:                 if (iwa1[numinc + 1] > 0) {
242:                     iwa2[iwa1[numinc + 1]] = ic;
243:                 }
244:                 iwa1[numinc + 1] = ic;
245:             }
246:         }
247:     }

249: /*        End of iteration loop. */

251:     goto L30;
252: L100:

254: /*     Invert the array list. */

256:     i__1 = *n;
257:     for (jcol = 1; jcol <= i__1; ++jcol) {
258:         iwa2[list[jcol]] = jcol;
259:     }
260:     i__1 = *n;
261:     for (jp = 1; jp <= i__1; ++jp) {
262:         list[jp] = iwa2[jp];
263:     }
264:     return(0);
265: }