Actual source code: sprcm.c

  2: #include <petscmat.h>
  3: #include <../src/mat/order/order.h>

  6: /*
  7:     MatGetOrdering_RCM - Find the Reverse Cuthill-McKee ordering of a given matrix.
  8: */
 11: PetscErrorCode  MatGetOrdering_RCM(Mat mat,const MatOrderingType type,IS *row,IS *col)
 12: {
 14:   PetscInt       i,*mask,*xls,nrow,*ia,*ja,*perm;
 15:   PetscBool      done;

 18:   MatGetRowIJ(mat,1,PETSC_TRUE,PETSC_TRUE,&nrow,&ia,&ja,&done);
 19:   if (!done) SETERRQ(((PetscObject)mat)->comm,PETSC_ERR_SUP,"Cannot get rows for matrix");

 21:   PetscMalloc3(nrow,PetscInt,&mask,nrow,PetscInt,&perm,2*nrow,PetscInt,&xls);
 22:   SPARSEPACKgenrcm(&nrow,ia,ja,perm,mask,xls);
 23:   MatRestoreRowIJ(mat,1,PETSC_TRUE,PETSC_TRUE,&nrow,&ia,&ja,&done);

 25:   /* shift because Sparsepack indices start at one */
 26:   for (i=0; i<nrow; i++) perm[i]--;
 27:   ISCreateGeneral(PETSC_COMM_SELF,nrow,perm,PETSC_COPY_VALUES,row);
 28:   ISCreateGeneral(PETSC_COMM_SELF,nrow,perm,PETSC_COPY_VALUES,col);
 29:   PetscFree3(mask,perm,xls);
 30:   return(0);
 31: }