1 2 #include "src/mat/impls/aij/seq/aij.h" 3 4 #undef __FUNCT__ 5 #define __FUNCT__ "MatToSymmetricIJ_SeqAIJ" 6 /* 7 MatToSymmetricIJ_SeqAIJ - Convert a (generally nonsymmetric) sparse AIJ matrix 8 to IJ format (ignore the "A" part) Allocates the space needed. Uses only 9 the lower triangular part of the matrix. 10 11 Description: 12 Take the data in the row-oriented sparse storage and build the 13 IJ data for the Matrix. Return 0 on success,row + 1 on failure 14 at that row. Produces the ij for a symmetric matrix by only using 15 the lower triangular part of the matrix. 16 17 Input Parameters: 18 . Matrix - matrix to convert 19 . shiftin - the shift for the original matrix (0 or 1) 20 . shiftout - the shift required for the ordering routine (0 or 1) 21 22 Output Parameters: 23 . ia - ia part of IJ representation (row information) 24 . ja - ja part (column indices) 25 26 Notes: 27 Both ia and ja may be freed with PetscFree(); 28 This routine is provided for ordering routines that require a 29 symmetric structure. It is required since those routines call 30 SparsePak routines that expect a symmetric matrix. 31 */ 32 PetscErrorCode MatToSymmetricIJ_SeqAIJ(int m,int *ai,int *aj,int shiftin,int shiftout,int **iia,int **jja) 33 { 34 int *work,*ia,*ja,*j,i,nz,row,col,ierr; 35 36 PetscFunctionBegin; 37 /* allocate space for row pointers */ 38 ierr = PetscMalloc((m+1)*sizeof(int),&ia);CHKERRQ(ierr); 39 *iia = ia; 40 ierr = PetscMemzero(ia,(m+1)*sizeof(int));CHKERRQ(ierr); 41 ierr = PetscMalloc((m+1)*sizeof(int),&work);CHKERRQ(ierr); 42 43 /* determine the number of columns in each row */ 44 ia[0] = shiftout; 45 for (row = 0; row < m; row++) { 46 nz = ai[row+1] - ai[row]; 47 j = aj + ai[row] + shiftin; 48 while (nz--) { 49 col = *j++ + shiftin; 50 if (col > row) { break;} 51 if (col != row) ia[row+1]++; 52 ia[col+1]++; 53 } 54 } 55 56 /* shiftin ia[i] to point to next row */ 57 for (i=1; i<m+1; i++) { 58 row = ia[i-1]; 59 ia[i] += row; 60 work[i-1] = row - shiftout; 61 } 62 63 /* allocate space for column pointers */ 64 nz = ia[m] + (!shiftin); 65 ierr = PetscMalloc(nz*sizeof(int),&ja);CHKERRQ(ierr); 66 *jja = ja; 67 68 /* loop over lower triangular part putting into ja */ 69 for (row = 0; row < m; row++) { 70 nz = ai[row+1] - ai[row]; 71 j = aj + ai[row] + shiftin; 72 while (nz--) { 73 col = *j++ + shiftin; 74 if (col > row) { break;} 75 if (col != row) {ja[work[col]++] = row + shiftout; } 76 ja[work[row]++] = col + shiftout; 77 } 78 } 79 ierr = PetscFree(work);CHKERRQ(ierr); 80 PetscFunctionReturn(0); 81 } 82 83 84 85