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,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:   PetscMalloc4(nrow,PetscInt,&mask,nrow,PetscInt,&perm,nrow+1,PetscInt,&xls,nrow,PetscInt,&ls);
 23:   SPARSEPACKgennd(&nrow,ia,ja,mask,perm,xls,ls);
 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]--;

 29:   ISCreateGeneral(PETSC_COMM_SELF,nrow,perm,row);
 30:   ISCreateGeneral(PETSC_COMM_SELF,nrow,perm,col);
 31:   PetscFree4(mask,perm,xls,ls);
 32:   return(0);
 33: }