xref: /petsc/src/mat/impls/aij/seq/ij.c (revision 5615d1e584023db9367fb782d85b1b4ebbb8df18)
1cb512458SBarry Smith #ifndef lint
2*5615d1e5SSatish Balay static char vcid[] = "$Id: ij.c,v 1.25 1996/12/17 23:39:44 balay Exp balay $";
3cb512458SBarry Smith #endif
4d6dfbf8fSBarry Smith 
570f55243SBarry Smith #include "src/mat/impls/aij/seq/aij.h"
62d9e4a2aSBarry Smith 
7*5615d1e5SSatish Balay #undef __FUNC__
8*5615d1e5SSatish Balay #define __FUNC__ "MatToSymmetricIJ_SeqAIJ"
92d9e4a2aSBarry Smith /*
103b2fbd54SBarry Smith   MatToSymmetricIJ_SeqAIJ - Convert a (generally nonsymmetric) sparse AIJ matrix
113b2fbd54SBarry Smith            to IJ format (ignore the "A" part) Allocates the space needed. Uses only
12d5d45c9bSBarry Smith            the lower triangular part of the matrix.
132d9e4a2aSBarry Smith 
142d9e4a2aSBarry Smith     Description:
152d9e4a2aSBarry Smith     Take the data in the row-oriented sparse storage and build the
162d9e4a2aSBarry Smith     IJ data for the Matrix.  Return 0 on success, row + 1 on failure
172d9e4a2aSBarry Smith     at that row. Produces the ij for a symmetric matrix by only using
182d9e4a2aSBarry Smith     the lower triangular part of the matrix.
192d9e4a2aSBarry Smith 
202d9e4a2aSBarry Smith     Input Parameters:
212d9e4a2aSBarry Smith .   Matrix - matrix to convert
22bcd2baecSBarry Smith .   shiftin - the shift for the original matrix (0 or 1)
23bcd2baecSBarry Smith .   shiftout - the shift required for the reordering routine (0 or 1)
242d9e4a2aSBarry Smith 
252d9e4a2aSBarry Smith     Output Parameters:
262d9e4a2aSBarry Smith .   ia     - ia part of IJ representation (row information)
272d9e4a2aSBarry Smith .   ja     - ja part (column indices)
282d9e4a2aSBarry Smith 
292d9e4a2aSBarry Smith     Notes:
300452661fSBarry Smith $    Both ia and ja may be freed with PetscFree();
31464493b3SBarry Smith $    This routine is provided for ordering routines that require a
32bcd2baecSBarry Smith $    symmetric structure.  It is required since those routines call
33bcd2baecSBarry Smith $    SparsePak routines that expect a symmetric  matrix.
342d9e4a2aSBarry Smith */
3531625ec5SSatish Balay int MatToSymmetricIJ_SeqAIJ(int m,int *ai,int *aj,int shiftin, int shiftout,
36bcd2baecSBarry Smith                             int **iia, int **jja )
372d9e4a2aSBarry Smith {
3835aab85fSBarry Smith   int *work,*ia,*ja,*j,i, nz, row, col;
392d9e4a2aSBarry Smith 
402d9e4a2aSBarry Smith   /* allocate space for row pointers */
4131625ec5SSatish Balay   *iia = ia = (int *) PetscMalloc( (m+1)*sizeof(int) ); CHKPTRQ(ia);
4231625ec5SSatish Balay   PetscMemzero(ia,(m+1)*sizeof(int));
4331625ec5SSatish Balay   work = (int *) PetscMalloc( (m+1)*sizeof(int) ); CHKPTRQ(work);
442d9e4a2aSBarry Smith 
452d9e4a2aSBarry Smith   /* determine the number of columns in each row */
463b2fbd54SBarry Smith   ia[0] = shiftout;
4731625ec5SSatish Balay   for (row = 0; row < m; row++) {
483439631bSBarry Smith     nz = ai[row+1] - ai[row];
490b6503f3SSatish Balay     j  = aj + ai[row] + shiftin;
502d9e4a2aSBarry Smith     while (nz--) {
5117603e33SSatish Balay        col = *j++ + shiftin;
52416022c9SBarry Smith        if (col > row) { break;}
532d9e4a2aSBarry Smith        if (col != row) ia[row+1]++;
542d9e4a2aSBarry Smith        ia[col+1]++;
552d9e4a2aSBarry Smith     }
562d9e4a2aSBarry Smith   }
572d9e4a2aSBarry Smith 
58bcd2baecSBarry Smith   /* shiftin ia[i] to point to next row */
5931625ec5SSatish Balay   for ( i=1; i<m+1; i++ ) {
600b6503f3SSatish Balay     row       = ia[i-1];
612d9e4a2aSBarry Smith     ia[i]     += row;
620b6503f3SSatish Balay     work[i-1] = row - shiftout;
632d9e4a2aSBarry Smith   }
642d9e4a2aSBarry Smith 
652d9e4a2aSBarry Smith   /* allocate space for column pointers */
6631625ec5SSatish Balay   nz = ia[m] + (!shiftin);
670452661fSBarry Smith   *jja = ja = (int *) PetscMalloc( nz*sizeof(int) ); CHKPTRQ(ja);
682d9e4a2aSBarry Smith 
692d9e4a2aSBarry Smith   /* loop over lower triangular part putting into ja */
7031625ec5SSatish Balay   for (row = 0; row < m; row++) {
713439631bSBarry Smith     nz = ai[row+1] - ai[row];
720b6503f3SSatish Balay     j  = aj + ai[row] + shiftin;
732d9e4a2aSBarry Smith     while (nz--) {
7417603e33SSatish Balay       col = *j++ + shiftin;
75416022c9SBarry Smith       if (col > row) { break;}
763b2fbd54SBarry Smith       if (col != row) {ja[work[col]++] = row + shiftout; }
773b2fbd54SBarry Smith       ja[work[row]++] = col + shiftout;
782d9e4a2aSBarry Smith     }
792d9e4a2aSBarry Smith   }
800452661fSBarry Smith   PetscFree(work);
812d9e4a2aSBarry Smith   return 0;
822d9e4a2aSBarry Smith }
832d9e4a2aSBarry Smith 
84d5d45c9bSBarry Smith 
85d5d45c9bSBarry Smith 
86