1a5eb4965SSatish Balay #ifdef PETSC_RCS_HEADER 2*b833fc0dSLois Curfman McInnes static char vcid[] = "$Id: ij.c,v 1.29 1999/03/11 16:18:58 bsmith Exp curfman $"; 3cb512458SBarry Smith #endif 4d6dfbf8fSBarry Smith 570f55243SBarry Smith #include "src/mat/impls/aij/seq/aij.h" 62d9e4a2aSBarry Smith 75615d1e5SSatish Balay #undef __FUNC__ 85615d1e5SSatish 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) 2391e9ee9fSBarry Smith . shiftout - the shift required for the ordering 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: 30*b833fc0dSLois Curfman McInnes Both ia and ja may be freed with PetscFree(); 31*b833fc0dSLois Curfman McInnes This routine is provided for ordering routines that require a 32*b833fc0dSLois Curfman McInnes symmetric structure. It is required since those routines call 33*b833fc0dSLois Curfman McInnes 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 403a40ed3dSBarry Smith PetscFunctionBegin; 412d9e4a2aSBarry Smith /* allocate space for row pointers */ 4231625ec5SSatish Balay *iia = ia = (int *) PetscMalloc( (m+1)*sizeof(int) ); CHKPTRQ(ia); 4331625ec5SSatish Balay PetscMemzero(ia,(m+1)*sizeof(int)); 4431625ec5SSatish Balay work = (int *) PetscMalloc( (m+1)*sizeof(int) ); CHKPTRQ(work); 452d9e4a2aSBarry Smith 462d9e4a2aSBarry Smith /* determine the number of columns in each row */ 473b2fbd54SBarry Smith ia[0] = shiftout; 4831625ec5SSatish Balay for (row = 0; row < m; row++) { 493439631bSBarry Smith nz = ai[row+1] - ai[row]; 500b6503f3SSatish Balay j = aj + ai[row] + shiftin; 512d9e4a2aSBarry Smith while (nz--) { 5217603e33SSatish Balay col = *j++ + shiftin; 53416022c9SBarry Smith if (col > row) { break;} 542d9e4a2aSBarry Smith if (col != row) ia[row+1]++; 552d9e4a2aSBarry Smith ia[col+1]++; 562d9e4a2aSBarry Smith } 572d9e4a2aSBarry Smith } 582d9e4a2aSBarry Smith 59bcd2baecSBarry Smith /* shiftin ia[i] to point to next row */ 6031625ec5SSatish Balay for ( i=1; i<m+1; i++ ) { 610b6503f3SSatish Balay row = ia[i-1]; 622d9e4a2aSBarry Smith ia[i] += row; 630b6503f3SSatish Balay work[i-1] = row - shiftout; 642d9e4a2aSBarry Smith } 652d9e4a2aSBarry Smith 662d9e4a2aSBarry Smith /* allocate space for column pointers */ 6731625ec5SSatish Balay nz = ia[m] + (!shiftin); 680452661fSBarry Smith *jja = ja = (int *) PetscMalloc( nz*sizeof(int) ); CHKPTRQ(ja); 692d9e4a2aSBarry Smith 702d9e4a2aSBarry Smith /* loop over lower triangular part putting into ja */ 7131625ec5SSatish Balay for (row = 0; row < m; row++) { 723439631bSBarry Smith nz = ai[row+1] - ai[row]; 730b6503f3SSatish Balay j = aj + ai[row] + shiftin; 742d9e4a2aSBarry Smith while (nz--) { 7517603e33SSatish Balay col = *j++ + shiftin; 76416022c9SBarry Smith if (col > row) { break;} 773b2fbd54SBarry Smith if (col != row) {ja[work[col]++] = row + shiftout; } 783b2fbd54SBarry Smith ja[work[row]++] = col + shiftout; 792d9e4a2aSBarry Smith } 802d9e4a2aSBarry Smith } 810452661fSBarry Smith PetscFree(work); 823a40ed3dSBarry Smith PetscFunctionReturn(0); 832d9e4a2aSBarry Smith } 842d9e4a2aSBarry Smith 85d5d45c9bSBarry Smith 86d5d45c9bSBarry Smith 87