Actual source code: seq.c

      1: /* seq.f -- translated by f2c (version of 25 March 1992  12:58:56). */

      3: #include <../src/mat/graphops/color/impls/minpack/color.h>

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

     10:   /* Local variables */
     11:   PetscInt jcol, j, ic, ip, jp, ir;

     13:   /*     Given the sparsity pattern of an m by n matrix A, this */
     14:   /*     subroutine determines a consistent partition of the */
     15:   /*     columns of A by a sequential algorithm. */
     16:   /*     A consistent partition is defined in terms of the loopless */
     17:   /*     graph G with vertices a(j), j = 1,2,...,n where a(j) is the */
     18:   /*     j-th column of A and with edge (a(i),a(j)) if and only if */
     19:   /*     columns i and j have a non-zero in the same row position. */
     20:   /*     A partition of the columns of A into groups is consistent */
     21:   /*     if the columns in any group are not adjacent in the graph G. */
     22:   /*     In graph-theory terminology, a consistent partition of the */
     23:   /*     columns of A corresponds to a coloring of the graph G. */
     24:   /*     The subroutine examines the columns in the order specified */
     25:   /*     by the array list, and assigns the current column to the */
     26:   /*     group with the smallest possible number. */
     27:   /*     Note that the value of m is not needed by seq and is */
     28:   /*     therefore not present in the subroutine statement. */
     29:   /*     The subroutine statement is */
     30:   /*       subroutine seq(n,indrow,jpntr,indcol,ipntr,list,ngrp,maxgrp, */
     31:   /*                      iwa) */
     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:   /*       list is an integer input array of length n which specifies */
     52:   /*         the order to be used by the sequential algorithm. */
     53:   /*         The j-th column in this order is list(j). */
     54:   /*       ngrp is an integer output array of length n which specifies */
     55:   /*         the partition of the columns of A. Column jcol belongs */
     56:   /*         to group ngrp(jcol). */
     57:   /*       maxgrp is an integer output variable which specifies the */
     58:   /*         number of groups in the partition of the columns of A. */
     59:   /*       iwa is an integer work array of length n. */
     60:   /*     Argonne National Laboratory. MINPACK Project. July 1983. */
     61:   /*     Thomas F. Coleman, Burton S. Garbow, Jorge J. More' */

     63:   PetscFunctionBegin;
     64:   /* Parameter adjustments */
     65:   --iwa;
     66:   --ngrp;
     67:   --list;
     68:   --ipntr;
     69:   --indcol;
     70:   --jpntr;
     71:   --indrow;

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

     81:   /*     Beginning of iteration loop. */

     83:   i__1 = *n;
     84:   for (j = 1; j <= i__1; ++j) {
     85:     jcol = list[j];

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

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

     92:     i__2 = jpntr[jcol + 1] - 1;
     93:     for (jp = jpntr[jcol]; jp <= i__2; ++jp) {
     94:       ir = indrow[jp];

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

     99:       i__3 = ipntr[ir + 1] - 1;
    100:       for (ip = ipntr[ir]; ip <= i__3; ++ip) {
    101:         ic = indcol[ip];

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

    106:         iwa[ngrp[ic]] = j;
    107:       }
    108:     }

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

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

    121:   /*        End of iteration loop. */
    122:   PetscFunctionReturn(PETSC_SUCCESS);
    123: }