1cb512458SBarry Smith #ifndef lint 2*ec8511deSBarry Smith static char vcid[] = "$Id: ij.c,v 1.8 1995/08/15 20:28:05 bsmith Exp bsmith $"; 3cb512458SBarry Smith #endif 4d6dfbf8fSBarry Smith 52d9e4a2aSBarry Smith #include "aij.h" 62d9e4a2aSBarry Smith 72d9e4a2aSBarry Smith /* 8*ec8511deSBarry Smith MatToSymmetricIJ_SeqAIJ - Convert a sparse AIJ matrix to IJ format 92d9e4a2aSBarry Smith (ignore the "A" part) 102d9e4a2aSBarry Smith Allocates the space needed. Uses only the lower triangular 112d9e4a2aSBarry Smith part of the matrix. 122d9e4a2aSBarry Smith 132d9e4a2aSBarry Smith Description: 142d9e4a2aSBarry Smith Take the data in the row-oriented sparse storage and build the 152d9e4a2aSBarry Smith IJ data for the Matrix. Return 0 on success, row + 1 on failure 162d9e4a2aSBarry Smith at that row. Produces the ij for a symmetric matrix by only using 172d9e4a2aSBarry Smith the lower triangular part of the matrix. 182d9e4a2aSBarry Smith 192d9e4a2aSBarry Smith Input Parameters: 202d9e4a2aSBarry Smith . Matrix - matrix to convert 212d9e4a2aSBarry Smith 222d9e4a2aSBarry Smith Output Parameters: 232d9e4a2aSBarry Smith . ia - ia part of IJ representation (row information) 242d9e4a2aSBarry Smith . ja - ja part (column indices) 252d9e4a2aSBarry Smith 262d9e4a2aSBarry Smith Notes: 27464493b3SBarry Smith $ Both ia and ja maybe freed with PETSCFREE(); 28464493b3SBarry Smith $ This routine is provided for ordering routines that require a 29464493b3SBarry Smith $ symmetric structure. It is used in SpOrder (and derivatives) since 30464493b3SBarry Smith $ those routines call SparsePak routines that expect a symmetric 31464493b3SBarry Smith $ matrix. 322d9e4a2aSBarry Smith */ 33*ec8511deSBarry Smith int MatToSymmetricIJ_SeqAIJ( Mat_SeqAIJ *Matrix, int **iia, int **jja ) 342d9e4a2aSBarry Smith { 352d9e4a2aSBarry Smith int *work,*ia,*ja,*j,i, nz, n, row, wr; 362d9e4a2aSBarry Smith register int col; 372d9e4a2aSBarry Smith 382d9e4a2aSBarry Smith n = Matrix->m; 392d9e4a2aSBarry Smith 402d9e4a2aSBarry Smith /* allocate space for row pointers */ 4178b31e54SBarry Smith *iia = ia = (int *) PETSCMALLOC( (n+1)*sizeof(int) ); CHKPTRQ(ia); 4278b31e54SBarry Smith PETSCMEMSET(ia,0,(n+1)*sizeof(int)); 4378b31e54SBarry Smith work = (int *) PETSCMALLOC( (n+1)*sizeof(int) ); CHKPTRQ(work); 442d9e4a2aSBarry Smith 452d9e4a2aSBarry Smith /* determine the number of columns in each row */ 462d9e4a2aSBarry Smith ia[0] = 1; 472d9e4a2aSBarry Smith for (row = 0; row < n; row++) { 482d9e4a2aSBarry Smith nz = Matrix->i[row+1] - Matrix->i[row]; 492d9e4a2aSBarry Smith j = Matrix->j + Matrix->i[row] - 1; 502d9e4a2aSBarry Smith while (nz--) { 51289bc588SBarry Smith col = *j++ - 1; 522d9e4a2aSBarry Smith if ( col > row ) { 532d9e4a2aSBarry Smith break; 542d9e4a2aSBarry Smith } 552d9e4a2aSBarry Smith if (col != row) ia[row+1]++; 562d9e4a2aSBarry Smith ia[col+1]++; 572d9e4a2aSBarry Smith } 582d9e4a2aSBarry Smith } 592d9e4a2aSBarry Smith 602d9e4a2aSBarry Smith /* shift ia[i] to point to next row */ 612d9e4a2aSBarry Smith for ( i=1; i<n+1; i++ ) { 622d9e4a2aSBarry Smith row = ia[i-1]; 632d9e4a2aSBarry Smith ia[i] += row; 642d9e4a2aSBarry Smith work[i-1] = row - 1; 652d9e4a2aSBarry Smith } 662d9e4a2aSBarry Smith 672d9e4a2aSBarry Smith /* allocate space for column pointers */ 682d9e4a2aSBarry Smith nz = ia[n]; 6978b31e54SBarry Smith *jja = ja = (int *) PETSCMALLOC( nz*sizeof(int) ); CHKPTRQ(ja); 702d9e4a2aSBarry Smith 712d9e4a2aSBarry Smith /* loop over lower triangular part putting into ja */ 722d9e4a2aSBarry Smith for (row = 0; row < n; row++) { 732d9e4a2aSBarry Smith nz = Matrix->i[row+1] - Matrix->i[row]; 742d9e4a2aSBarry Smith j = Matrix->j + Matrix->i[row] - 1; 752d9e4a2aSBarry Smith while (nz--) { 76289bc588SBarry Smith col = *j++ - 1; 772d9e4a2aSBarry Smith if ( col > row ) { 782d9e4a2aSBarry Smith break; 792d9e4a2aSBarry Smith } 802d9e4a2aSBarry Smith if (col != row) {wr = work[col]; work[col] = wr + 1; 812d9e4a2aSBarry Smith ja[wr] = row + 1; } 822d9e4a2aSBarry Smith wr = work[row]; work[row] = wr + 1; 832d9e4a2aSBarry Smith ja[wr] = col + 1; 842d9e4a2aSBarry Smith } 85289bc588SBarry Smith 862d9e4a2aSBarry Smith } 8778b31e54SBarry Smith PETSCFREE(work); 882d9e4a2aSBarry Smith return 0; 892d9e4a2aSBarry Smith } 902d9e4a2aSBarry Smith 91