Actual source code: sprcm.c

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

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

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

 21:   PetscMalloc(4*nrow * sizeof(PetscInt),&mask);
 22:   perm = mask + nrow;
 23:   xls  = perm + nrow;

 25:   SPARSEPACKgenrcm(&nrow,ia,ja,perm,mask,xls);
 26:   MatRestoreRowIJ(mat,1,PETSC_TRUE,&nrow,&ia,&ja,&done);

 28:   /* shift because Sparsepack indices start at one */
 29:   for (i=0; i<nrow; i++) perm[i]--;

 31:   ISCreateGeneral(PETSC_COMM_SELF,nrow,perm,row);
 32:   ISCreateGeneral(PETSC_COMM_SELF,nrow,perm,col);
 33:   PetscFree(mask);

 35:   return(0);
 36: }