1cb512458SBarry Smith #ifndef lint 2*78b31e54SBarry Smith static char vcid[] = "$Id: ij.c,v 1.6 1995/05/21 19:55:41 curfman Exp bsmith $"; 3cb512458SBarry Smith #endif 4d6dfbf8fSBarry Smith 52d9e4a2aSBarry Smith #include "aij.h" 62d9e4a2aSBarry Smith 72d9e4a2aSBarry Smith /* 8c124c9a6SLois Curfman McInnes SpToSymmetricIJ_AIJ - 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: 272d9e4a2aSBarry Smith This routine is provided for ordering routines that require a 282d9e4a2aSBarry Smith symmetric structure. It is used in SpOrder (and derivatives) since 292d9e4a2aSBarry Smith those routines call SparsePak routines that expect a symmetric 302d9e4a2aSBarry Smith matrix. 312d9e4a2aSBarry Smith */ 32c124c9a6SLois Curfman McInnes int SpToSymmetricIJ_AIJ( Mat_AIJ *Matrix, int **iia, int **jja ) 332d9e4a2aSBarry Smith { 342d9e4a2aSBarry Smith int *work,*ia,*ja,*j,i, nz, n, row, wr; 352d9e4a2aSBarry Smith register int col; 362d9e4a2aSBarry Smith 372d9e4a2aSBarry Smith n = Matrix->m; 382d9e4a2aSBarry Smith 392d9e4a2aSBarry Smith /* allocate space for row pointers */ 40*78b31e54SBarry Smith *iia = ia = (int *) PETSCMALLOC( (n+1)*sizeof(int) ); CHKPTRQ(ia); 41*78b31e54SBarry Smith PETSCMEMSET(ia,0,(n+1)*sizeof(int)); 42*78b31e54SBarry Smith work = (int *) PETSCMALLOC( (n+1)*sizeof(int) ); CHKPTRQ(work); 432d9e4a2aSBarry Smith 442d9e4a2aSBarry Smith /* determine the number of columns in each row */ 452d9e4a2aSBarry Smith ia[0] = 1; 462d9e4a2aSBarry Smith for (row = 0; row < n; row++) { 472d9e4a2aSBarry Smith nz = Matrix->i[row+1] - Matrix->i[row]; 482d9e4a2aSBarry Smith j = Matrix->j + Matrix->i[row] - 1; 492d9e4a2aSBarry Smith while (nz--) { 50289bc588SBarry Smith col = *j++ - 1; 512d9e4a2aSBarry Smith if ( col > row ) { 522d9e4a2aSBarry Smith break; 532d9e4a2aSBarry Smith } 542d9e4a2aSBarry Smith if (col != row) ia[row+1]++; 552d9e4a2aSBarry Smith ia[col+1]++; 562d9e4a2aSBarry Smith } 572d9e4a2aSBarry Smith } 582d9e4a2aSBarry Smith 592d9e4a2aSBarry Smith /* shift ia[i] to point to next row */ 602d9e4a2aSBarry Smith for ( i=1; i<n+1; i++ ) { 612d9e4a2aSBarry Smith row = ia[i-1]; 622d9e4a2aSBarry Smith ia[i] += row; 632d9e4a2aSBarry Smith work[i-1] = row - 1; 642d9e4a2aSBarry Smith } 652d9e4a2aSBarry Smith 662d9e4a2aSBarry Smith /* allocate space for column pointers */ 672d9e4a2aSBarry Smith nz = ia[n]; 68*78b31e54SBarry Smith *jja = ja = (int *) PETSCMALLOC( nz*sizeof(int) ); CHKPTRQ(ja); 692d9e4a2aSBarry Smith 702d9e4a2aSBarry Smith /* loop over lower triangular part putting into ja */ 712d9e4a2aSBarry Smith for (row = 0; row < n; row++) { 722d9e4a2aSBarry Smith nz = Matrix->i[row+1] - Matrix->i[row]; 732d9e4a2aSBarry Smith j = Matrix->j + Matrix->i[row] - 1; 742d9e4a2aSBarry Smith while (nz--) { 75289bc588SBarry Smith col = *j++ - 1; 762d9e4a2aSBarry Smith if ( col > row ) { 772d9e4a2aSBarry Smith break; 782d9e4a2aSBarry Smith } 792d9e4a2aSBarry Smith if (col != row) {wr = work[col]; work[col] = wr + 1; 802d9e4a2aSBarry Smith ja[wr] = row + 1; } 812d9e4a2aSBarry Smith wr = work[row]; work[row] = wr + 1; 822d9e4a2aSBarry Smith ja[wr] = col + 1; 832d9e4a2aSBarry Smith } 84289bc588SBarry Smith 852d9e4a2aSBarry Smith } 86*78b31e54SBarry Smith PETSCFREE(work); 872d9e4a2aSBarry Smith return 0; 882d9e4a2aSBarry Smith } 892d9e4a2aSBarry Smith 90