Actual source code: sp1wd.c

petsc-3.4.5 2014-06-29
  2: #include <petscmat.h>
  3: #include <../src/mat/order/order.h>

  5: /*
  6:     MatGetOrdering_1WD - Find the 1-way dissection ordering of a given matrix.
  7: */
 10: PETSC_EXTERN PetscErrorCode MatGetOrdering_1WD(Mat mat,MatOrderingType type,IS *row,IS *col)
 11: {
 13:   PetscInt       i,*mask,*xls,nblks,*xblk,*ls,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:   PetscMalloc5(nrow,PetscInt,&mask,nrow+1,PetscInt,&xls,nrow,PetscInt,&ls,nrow+1,PetscInt,&xblk,nrow,PetscInt,&perm);
 22:   SPARSEPACKgen1wd(&nrow,ia,ja,mask,&nblks,xblk,perm,xls,ls);
 23:   MatRestoreRowIJ(mat,1,PETSC_TRUE,PETSC_TRUE,NULL,&ia,&ja,&done);

 25:   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:   PetscFree5(mask,xls,ls,xblk,perm);
 30:   return(0);
 31: }