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,PETSC_TRUE,&nrow,&ia,&ja,&done);
20: if (!done) SETERRQ(PETSC_ERR_SUP,"Cannot get rows for matrix");
22: PetscMalloc3(nrow,PetscInt,&mask,nrow,PetscInt,&perm,2*nrow,PetscInt,&xls);
23: SPARSEPACKgenrcm(&nrow,ia,ja,perm,mask,xls);
24: MatRestoreRowIJ(mat,1,PETSC_TRUE,PETSC_TRUE,&nrow,&ia,&ja,&done);
26: /* shift because Sparsepack indices start at one */
27: for (i=0; i<nrow; i++) perm[i]--;
28: ISCreateGeneral(PETSC_COMM_SELF,nrow,perm,row);
29: ISCreateGeneral(PETSC_COMM_SELF,nrow,perm,col);
30: PetscFree3(mask,perm,xls);
31: return(0);
32: }