Actual source code: sprcm.c

  1: #define PETSCMAT_DLL

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

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

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

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

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

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

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

 36:   return(0);
 37: }