Actual source code: spnd.c

  1: #define PETSCMAT_DLL

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

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

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

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

 27:   SPARSEPACKgennd(&nrow,ia,ja,mask,perm,xls,ls);
 28:   MatRestoreRowIJ(mat,1,PETSC_TRUE,&nrow,&ia,&ja,&done);

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

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

 37:   return(0);
 38: }