Actual source code: seq.c

petsc-3.4.5 2014-06-29
  2: /* seq.f -- translated by f2c (version of 25 March 1992  12:58:56).*/

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

  8: PetscErrorCode MINPACKseq(PetscInt *n,const PetscInt *indrow,const PetscInt *jpntr,const PetscInt *indcol,const PetscInt *ipntr,PetscInt *list,PetscInt *ngrp,PetscInt *maxgrp,PetscInt *iwa)
  9: {
 10:   /* System generated locals */
 11:   PetscInt i__1, i__2, i__3;

 13:   /* Local variables */
 14:   PetscInt jcol, j, ic, ip, jp, ir;

 16: /*     Given the sparsity pattern of an m by n matrix A, this */
 17: /*     subroutine determines a consistent partition of the */
 18: /*     columns of A by a sequential algorithm. */
 19: /*     A consistent partition is defined in terms of the loopless */
 20: /*     graph G with vertices a(j), j = 1,2,...,n where a(j) is the */
 21: /*     j-th column of A and with edge (a(i),a(j)) if and only if */
 22: /*     columns i and j have a non-zero in the same row position. */
 23: /*     A partition of the columns of A into groups is consistent */
 24: /*     if the columns in any group are not adjacent in the graph G. */
 25: /*     In graph-theory terminology, a consistent partition of the */
 26: /*     columns of A corresponds to a coloring of the graph G. */
 27: /*     The subroutine examines the columns in the order specified */
 28: /*     by the array list, and assigns the current column to the */
 29: /*     group with the smallest possible number. */
 30: /*     Note that the value of m is not needed by seq and is */
 31: /*     therefore not present in the subroutine statement. */
 32: /*     The subroutine statement is */
 33: /*       subroutine seq(n,indrow,jpntr,indcol,ipntr,list,ngrp,maxgrp, */
 34: /*                      iwa) */
 35: /*     where */
 36: /*       n is a positive integer input variable set to the number */
 37: /*         of columns of A. */
 38: /*       indrow is an integer input array which contains the row */
 39: /*         indices for the non-zeroes in the matrix A. */
 40: /*       jpntr is an integer input array of length n + 1 which */
 41: /*         specifies the locations of the row indices in indrow. */
 42: /*         The row indices for column j are */
 43: /*               indrow(k), k = jpntr(j),...,jpntr(j+1)-1. */
 44: /*         Note that jpntr(n+1)-1 is then the number of non-zero */
 45: /*         elements of the matrix A. */
 46: /*       indcol is an integer input array which contains the */
 47: /*         column indices for the non-zeroes in the matrix A. */
 48: /*       ipntr is an integer input array of length m + 1 which */
 49: /*         specifies the locations of the column indices in indcol. */
 50: /*         The column indices for row i are */
 51: /*               indcol(k), k = ipntr(i),...,ipntr(i+1)-1. */
 52: /*         Note that ipntr(m+1)-1 is then the number of non-zero */
 53: /*         elements of the matrix A. */
 54: /*       list is an integer input array of length n which specifies */
 55: /*         the order to be used by the sequential algorithm. */
 56: /*         The j-th column in this order is list(j). */
 57: /*       ngrp is an integer output array of length n which specifies */
 58: /*         the partition of the columns of A. Column jcol belongs */
 59: /*         to group ngrp(jcol). */
 60: /*       maxgrp is an integer output variable which specifies the */
 61: /*         number of groups in the partition of the columns of A. */
 62: /*       iwa is an integer work array of length n. */
 63: /*     Argonne National Laboratory. MINPACK Project. July 1983. */
 64: /*     Thomas F. Coleman, Burton S. Garbow, Jorge J. More' */

 67:   /* Parameter adjustments */
 68:   --iwa;
 69:   --ngrp;
 70:   --list;
 71:   --ipntr;
 72:   --indcol;
 73:   --jpntr;
 74:   --indrow;

 76:   /* Function Body */
 77:   *maxgrp = 0;
 78:   i__1    = *n;
 79:   for (jp = 1; jp <= i__1; ++jp) {
 80:     ngrp[jp] = *n;
 81:     iwa[jp]  = 0;
 82:   }

 84:   /*     Beginning of iteration loop. */

 86:   i__1 = *n;
 87:   for (j = 1; j <= i__1; ++j) {
 88:     jcol = list[j];

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

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

 95:     i__2 = jpntr[jcol + 1] - 1;
 96:     for (jp = jpntr[jcol]; jp <= i__2; ++jp) {
 97:       ir = indrow[jp];

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

102:       i__3 = ipntr[ir + 1] - 1;
103:       for (ip = ipntr[ir]; ip <= i__3; ++ip) {
104:         ic = indcol[ip];

106:         /*              Array iwa marks the group numbers of the */
107:         /*              columns which are adjacent to column jcol. */

109:         iwa[ngrp[ic]] = j;
110:       }
111:     }

113:     /*        Assign the smallest un-marked group number to jcol. */

115:     i__2 = *maxgrp;
116:     for (jp = 1; jp <= i__2; ++jp) {
117:       if (iwa[jp] != j) goto L50;
118:     }
119:     ++(*maxgrp);
120: L50:
121:     ngrp[jcol] = jp;
122:   }

124:   /*        End of iteration loop. */
125:   return(0);
126: }