/*$Id: sro.c,v 1.10 2000/09/11 19:42:15 balay Exp hzhang $*/ #include "petscsys.h" #include "src/mat/impls/baij/seq/baij.h" #include "src/vec/vecimpl.h" #include "src/inline/spops.h" #include "sbaij.h" /* This function is used before applying a symmetric reordering to matrix A that is in SBAIJ format. The permutation is assumed to be symmetric, i.e., P = P^T (= inv(P)), so the permuted matrix P*A*inv(P)=P*A*P^T is ensured to be symmetric. The function is modified from sro.f of YSMP. The description from YSMP: C THE NONZERO ENTRIES OF THE MATRIX M ARE ASSUMED TO BE STORED C SYMMETRICALLY IN (IA,JA,A) FORMAT (I.E., NOT BOTH M(I,J) AND M(J,I) C ARE STORED IF I NE J). C C SRO DOES NOT REARRANGE THE ORDER OF THE ROWS, BUT DOES MOVE C NONZEROES FROM ONE ROW TO ANOTHER TO ENSURE THAT IF M(I,J) WILL BE C IN THE UPPER TRIANGLE OF M WITH RESPECT TO THE NEW ORDERING, THEN C M(I,J) IS STORED IN ROW I (AND THUS M(J,I) IS NOT STORED); WHEREAS C IF M(I,J) WILL BE IN THE STRICT LOWER TRIANGLE OF M, THEN M(J,I) IS C STORED IN ROW J (AND THUS M(I,J) IS NOT STORED). -- output: new index set (ai, aj, a) for A such that all nonzero A_(p(i),isp(k)) will be stored in the upper triangle. Note: matrix A is not permuted by this function! */ #undef __FUNC__ #define __FUNC__ "MatReorderingSeqSBAIJ" int MatReorderingSeqSBAIJ(Mat A,IS perm) { Mat_SeqSBAIJ *a=(Mat_SeqSBAIJ *)A->data; int *r,ierr,i,mbs=a->mbs,*ai=a->i,*aj=a->j,*rip,*riip; MatScalar *aa=a->a; Scalar ak; int *nzr,nz,jmin,jmax,j,k,ajk; IS iperm; /* inverse of perm */ PetscFunctionBegin; if (!mbs) PetscFunctionReturn(0); ierr = ISGetIndices(perm,&rip);CHKERRQ(ierr); ierr = ISInvertPermutation(perm,PETSC_DECIDE,&iperm);CHKERRQ(ierr); ierr = ISGetIndices(iperm,&riip);CHKERRQ(ierr); for (i=0; irow = perm; a->icol = perm; ierr = PetscObjectReference((PetscObject)perm);CHKERRQ(ierr); ierr = PetscObjectReference((PetscObject)perm);CHKERRQ(ierr); ierr= ISRestoreIndices(perm,&rip);CHKERRA(ierr); ierr = PetscFree(nzr);CHKERRA(ierr); ierr = PetscFree(r);CHKERRA(ierr); PetscFunctionReturn(0); }