Actual source code: sprcm.c

petsc-3.13.6 2020-09-29
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: */
  8: PETSC_INTERN PetscErrorCode MatGetOrdering_RCM(Mat mat,MatOrderingType type,IS *row,IS *col)
  9: {
 11:   PetscInt       i,*mask,*xls,nrow,*perm;
 12:   const PetscInt *ia,*ja;
 13:   PetscBool      done;

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

 19:   PetscMalloc3(nrow,&mask,nrow,&perm,2*nrow,&xls);
 20:   SPARSEPACKgenrcm(&nrow,ia,ja,perm,mask,xls);
 21:   MatRestoreRowIJ(mat,1,PETSC_TRUE,PETSC_TRUE,NULL,&ia,&ja,&done);

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