Actual source code: ij.c

  1: /*$Id: ij.c,v 1.38 2001/03/23 23:21:51 balay Exp $*/

 3:  #include src/mat/impls/aij/seq/aij.h

  5: /*
  6:   MatToSymmetricIJ_SeqAIJ - Convert a (generally nonsymmetric) sparse AIJ matrix
  7:            to IJ format (ignore the "A" part) Allocates the space needed. Uses only 
  8:            the lower triangular part of the matrix.

 10:     Description:
 11:     Take the data in the row-oriented sparse storage and build the
 12:     IJ data for the Matrix.  Return 0 on success,row + 1 on failure
 13:     at that row. Produces the ij for a symmetric matrix by only using
 14:     the lower triangular part of the matrix.

 16:     Input Parameters:
 17: .   Matrix - matrix to convert
 18: .   shiftin - the shift for the original matrix (0 or 1)
 19: .   shiftout - the shift required for the ordering routine (0 or 1)

 21:     Output Parameters:
 22: .   ia     - ia part of IJ representation (row information)
 23: .   ja     - ja part (column indices)

 25:     Notes:
 26:     Both ia and ja may be freed with PetscFree();
 27:     This routine is provided for ordering routines that require a 
 28:     symmetric structure.  It is required since those routines call 
 29:     SparsePak routines that expect a symmetric  matrix.
 30: */
 31: int MatToSymmetricIJ_SeqAIJ(int m,int *ai,int *aj,int shiftin,int shiftout,int **iia,int **jja)
 32: {
 33:   int *work,*ia,*ja,*j,i,nz,row,col,ierr;

 36:   /* allocate space for row pointers */
 37:   PetscMalloc((m+1)*sizeof(int),&ia);
 38:   *iia = ia;
 39:   PetscMemzero(ia,(m+1)*sizeof(int));
 40:   PetscMalloc((m+1)*sizeof(int),&work);

 42:   /* determine the number of columns in each row */
 43:   ia[0] = shiftout;
 44:   for (row = 0; row < m; row++) {
 45:     nz = ai[row+1] - ai[row];
 46:     j  = aj + ai[row] + shiftin;
 47:     while (nz--) {
 48:        col = *j++ + shiftin;
 49:        if (col > row) { break;}
 50:        if (col != row) ia[row+1]++;
 51:        ia[col+1]++;
 52:     }
 53:   }

 55:   /* shiftin ia[i] to point to next row */
 56:   for (i=1; i<m+1; i++) {
 57:     row       = ia[i-1];
 58:     ia[i]     += row;
 59:     work[i-1] = row - shiftout;
 60:   }

 62:   /* allocate space for column pointers */
 63:   nz   = ia[m] + (!shiftin);
 64:   PetscMalloc(nz*sizeof(int),&ja);
 65:   *jja = ja;

 67:   /* loop over lower triangular part putting into ja */
 68:   for (row = 0; row < m; row++) {
 69:     nz = ai[row+1] - ai[row];
 70:     j  = aj + ai[row] + shiftin;
 71:     while (nz--) {
 72:       col = *j++ + shiftin;
 73:       if (col > row) { break;}
 74:       if (col != row) {ja[work[col]++] = row + shiftout; }
 75:       ja[work[row]++] = col + shiftout;
 76:     }
 77:   }
 78:   PetscFree(work);
 79:   return(0);
 80: }