1*d6dfbf8fSBarry Smith 22d9e4a2aSBarry Smith 32d9e4a2aSBarry Smith #include "aij.h" 42d9e4a2aSBarry Smith 52d9e4a2aSBarry Smith /* 62d9e4a2aSBarry Smith SpToSymmetricIJ - Convert a sparse AIJ matrix to IJ format 72d9e4a2aSBarry Smith (ignore the "A" part) 82d9e4a2aSBarry Smith Allocates the space needed. Uses only the lower triangular 92d9e4a2aSBarry Smith part of the matrix. 102d9e4a2aSBarry Smith 112d9e4a2aSBarry Smith Description: 122d9e4a2aSBarry Smith Take the data in the row-oriented sparse storage and build the 132d9e4a2aSBarry Smith IJ data for the Matrix. Return 0 on success, row + 1 on failure 142d9e4a2aSBarry Smith at that row. Produces the ij for a symmetric matrix by only using 152d9e4a2aSBarry Smith the lower triangular part of the matrix. 162d9e4a2aSBarry Smith 172d9e4a2aSBarry Smith Input Parameters: 182d9e4a2aSBarry Smith . Matrix - matrix to convert 192d9e4a2aSBarry Smith 202d9e4a2aSBarry Smith Output Parameters: 212d9e4a2aSBarry Smith . ia - ia part of IJ representation (row information) 222d9e4a2aSBarry Smith . ja - ja part (column indices) 232d9e4a2aSBarry Smith 242d9e4a2aSBarry Smith Notes: 252d9e4a2aSBarry Smith This routine is provided for ordering routines that require a 262d9e4a2aSBarry Smith symmetric structure. It is used in SpOrder (and derivatives) since 272d9e4a2aSBarry Smith those routines call SparsePak routines that expect a symmetric 282d9e4a2aSBarry Smith matrix. 292d9e4a2aSBarry Smith */ 302d9e4a2aSBarry Smith int SpToSymmetricIJ( Matiaij *Matrix, int **iia, int **jja ) 312d9e4a2aSBarry Smith { 322d9e4a2aSBarry Smith int *work,*ia,*ja,*j,i, nz, n, row, wr; 332d9e4a2aSBarry Smith register int col; 342d9e4a2aSBarry Smith 352d9e4a2aSBarry Smith n = Matrix->m; 362d9e4a2aSBarry Smith 372d9e4a2aSBarry Smith /* allocate space for row pointers */ 382d9e4a2aSBarry Smith *iia = ia = (int *) MALLOC( (n+1)*sizeof(int) ); CHKPTR(ia); 392d9e4a2aSBarry Smith MEMSET(ia,0,(n+1)*sizeof(int)); 402d9e4a2aSBarry Smith work = (int *) MALLOC( (n+1)*sizeof(int) ); CHKPTR(work); 412d9e4a2aSBarry Smith 422d9e4a2aSBarry Smith /* determine the number of columns in each row */ 432d9e4a2aSBarry Smith ia[0] = 1; 442d9e4a2aSBarry Smith for (row = 0; row < n; row++) { 452d9e4a2aSBarry Smith nz = Matrix->i[row+1] - Matrix->i[row]; 462d9e4a2aSBarry Smith j = Matrix->j + Matrix->i[row] - 1; 472d9e4a2aSBarry Smith while (nz--) { 48289bc588SBarry Smith col = *j++ - 1; 492d9e4a2aSBarry Smith if ( col > row ) { 502d9e4a2aSBarry Smith break; 512d9e4a2aSBarry Smith } 522d9e4a2aSBarry Smith if (col != row) ia[row+1]++; 532d9e4a2aSBarry Smith ia[col+1]++; 542d9e4a2aSBarry Smith } 552d9e4a2aSBarry Smith } 562d9e4a2aSBarry Smith 572d9e4a2aSBarry Smith /* shift ia[i] to point to next row */ 582d9e4a2aSBarry Smith for ( i=1; i<n+1; i++ ) { 592d9e4a2aSBarry Smith row = ia[i-1]; 602d9e4a2aSBarry Smith ia[i] += row; 612d9e4a2aSBarry Smith work[i-1] = row - 1; 622d9e4a2aSBarry Smith } 632d9e4a2aSBarry Smith 642d9e4a2aSBarry Smith /* allocate space for column pointers */ 652d9e4a2aSBarry Smith nz = ia[n]; 662d9e4a2aSBarry Smith *jja = ja = (int *) MALLOC( nz*sizeof(int) ); CHKPTR(ja); 672d9e4a2aSBarry Smith 682d9e4a2aSBarry Smith /* loop over lower triangular part putting into ja */ 692d9e4a2aSBarry Smith for (row = 0; row < n; row++) { 702d9e4a2aSBarry Smith nz = Matrix->i[row+1] - Matrix->i[row]; 712d9e4a2aSBarry Smith j = Matrix->j + Matrix->i[row] - 1; 722d9e4a2aSBarry Smith while (nz--) { 73289bc588SBarry Smith col = *j++ - 1; 742d9e4a2aSBarry Smith if ( col > row ) { 752d9e4a2aSBarry Smith break; 762d9e4a2aSBarry Smith } 772d9e4a2aSBarry Smith if (col != row) {wr = work[col]; work[col] = wr + 1; 782d9e4a2aSBarry Smith ja[wr] = row + 1; } 792d9e4a2aSBarry Smith wr = work[row]; work[row] = wr + 1; 802d9e4a2aSBarry Smith ja[wr] = col + 1; 812d9e4a2aSBarry Smith } 82289bc588SBarry Smith 832d9e4a2aSBarry Smith } 842d9e4a2aSBarry Smith FREE(work); 852d9e4a2aSBarry Smith return 0; 862d9e4a2aSBarry Smith } 872d9e4a2aSBarry Smith 88