Actual source code: spqmd.c

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

  6: /*
  7:     MatGetOrdering_QMD - Find the Quotient Minimum Degree ordering of a given matrix.
  8: */
 11: PetscErrorCode  MatGetOrdering_QMD(Mat mat,const MatOrderingType type,IS *row,IS *col)
 12: {
 13:   PetscInt       i,  *deg,*marker,*rchset,*nbrhd,*qsize,*qlink,nofsub,*iperm,nrow;
 15:   PetscInt       *ia,*ja,*perm;
 16:   PetscBool       done;

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

 22:   PetscMalloc(nrow * sizeof(PetscInt),&perm);
 23:   PetscMalloc5(nrow,PetscInt,&iperm,nrow,PetscInt,&deg,nrow,PetscInt,&marker,nrow,PetscInt,&rchset,nrow,PetscInt,&nbrhd);
 24:   PetscMalloc2(nrow,PetscInt,&qsize,nrow,PetscInt,&qlink);
 25:   /* WARNING - genqmd trashes ja */
 26:   SPARSEPACKgenqmd(&nrow,ia,ja,perm,iperm,deg,marker,rchset,nbrhd,qsize,qlink,&nofsub);
 27:   MatRestoreRowIJ(mat,1,PETSC_TRUE,PETSC_TRUE,&nrow,&ia,&ja,&done);

 29:   PetscFree2(qsize,qlink);
 30:   PetscFree5(iperm,deg,marker,rchset,nbrhd);
 31:   for (i=0; i<nrow; i++) perm[i]--;
 32:   ISCreateGeneral(PETSC_COMM_SELF,nrow,perm,PETSC_COPY_VALUES,row);
 33:   ISCreateGeneral(PETSC_COMM_SELF,nrow,perm,PETSC_OWN_POINTER,col);
 34:   return(0);
 35: }