/* * ex193.c * * Created on: Jul 29, 2015 * Author: Fande Kong fdkong.jd@gmail.com */ /* * An example demonstrates how to use hierarchical partitioning approach */ #include static char help[] = "Illustrates use of hierarchical partitioning.\n"; int main(int argc,char **args) { Mat A; /* matrix */ PetscInt m,n; /* mesh dimensions in x- and y- directions */ PetscInt i,j,Ii,J,Istart,Iend; PetscErrorCode ierr; PetscMPIInt size; PetscScalar v; MatPartitioning part; IS coarseparts,fineparts; IS is,isn,isrows; MPI_Comm comm; PetscCall(PetscInitialize(&argc,&args,(char*)0,help)); comm = PETSC_COMM_WORLD; PetscCallMPI(MPI_Comm_size(comm,&size)); ierr = PetscOptionsBegin(comm,NULL,"ex193","hierarchical partitioning");PetscCall(ierr); m = 15; PetscCall(PetscOptionsInt("-M","Number of mesh points in the x-direction","partitioning",m,&m,NULL)); n = 15; PetscCall(PetscOptionsInt("-N","Number of mesh points in the y-direction","partitioning",n,&n,NULL)); ierr = PetscOptionsEnd();PetscCall(ierr); /* Assemble the matrix for the five point stencil (finite difference), YET AGAIN */ PetscCall(MatCreate(comm,&A)); PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m*n,m*n)); PetscCall(MatSetFromOptions(A)); PetscCall(MatSetUp(A)); PetscCall(MatGetOwnershipRange(A,&Istart,&Iend)); for (Ii=Istart; Ii0) {J = Ii - n; PetscCall(MatSetValues(A,1,&Ii,1,&J,&v,INSERT_VALUES));} if (i0) {J = Ii - 1; PetscCall(MatSetValues(A,1,&Ii,1,&J,&v,INSERT_VALUES));} if (j