Actual source code: sprcm.c

petsc-3.7.7 2017-09-25
Report Typos and Errors
  2: #include <petscmat.h>
  3: #include <petsc/private/matorderimpl.h>

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

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

 21:   PetscMalloc3(nrow,&mask,nrow,&perm,2*nrow,&xls);
 22:   SPARSEPACKgenrcm(&nrow,ia,ja,perm,mask,xls);
 23:   MatRestoreRowIJ(mat,1,PETSC_TRUE,PETSC_TRUE,NULL,&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: }