Actual source code: ex11.c


  2: static char help[] = "Tests MatMeshToDual()\n\n";

  4: /*T
  5:    Concepts: Mat^mesh partitioning
  6:    Processors: n
  7: T*/

  9: /*
 10:   Include "petscmat.h" so that we can use matrices.
 11:   automatically includes:
 12:      petscsys.h       - base PETSc routines   petscvec.h    - vectors
 13:      petscmat.h    - matrices
 14:      petscis.h     - index sets            petscviewer.h - viewers
 15: */
 16: #include <petscmat.h>

 18: int main(int argc,char **args)
 19: {
 20:   Mat             mesh,dual;
 21:   PetscInt        Nvertices = 6;       /* total number of vertices */
 22:   PetscInt        ncells    = 2;       /* number cells on this process */
 23:   PetscInt        *ii,*jj;
 24:   PetscMPIInt     size,rank;
 25:   MatPartitioning part;
 26:   IS              is;

 28:   PetscInitialize(&argc,&args,(char*)0,help);
 29:   MPI_Comm_size(MPI_COMM_WORLD,&size);
 31:   MPI_Comm_rank(MPI_COMM_WORLD,&rank);

 33:   PetscMalloc1(3,&ii);
 34:   PetscMalloc1(6,&jj);
 35:   ii[0] = 0; ii[1] = 3; ii[2] = 6;
 36:   if (rank == 0) {
 37:     jj[0] = 0; jj[1] = 1; jj[2] = 2; jj[3] = 1; jj[4] = 2; jj[5] = 3;
 38:   } else {
 39:     jj[0] = 1; jj[1] = 4; jj[2] = 5; jj[3] = 1; jj[4] = 3; jj[5] = 5;
 40:   }
 41:   MatCreateMPIAdj(MPI_COMM_WORLD,ncells,Nvertices,ii,jj,NULL,&mesh);
 42:   MatMeshToCellGraph(mesh,2,&dual);
 43:   MatView(dual,PETSC_VIEWER_STDOUT_WORLD);

 45:   MatPartitioningCreate(MPI_COMM_WORLD,&part);
 46:   MatPartitioningSetAdjacency(part,dual);
 47:   MatPartitioningSetFromOptions(part);
 48:   MatPartitioningApply(part,&is);
 49:   ISView(is,PETSC_VIEWER_STDOUT_WORLD);
 50:   ISDestroy(&is);
 51:   MatPartitioningDestroy(&part);

 53:   MatDestroy(&mesh);
 54:   MatDestroy(&dual);
 55:   PetscFinalize();
 56:   return 0;
 57: }

 59: /*TEST

 61:    build:
 62:      requires: parmetis

 64:    test:
 65:       nsize: 2
 66:       requires: parmetis

 68: TEST*/