Actual source code: ex11.c
2: static char help[] = "Tests MatMeshToDual()\n\n";
4: /*
5: Include "petscmat.h" so that we can use matrices.
6: automatically includes:
7: petscsys.h - base PETSc routines petscvec.h - vectors
8: petscmat.h - matrices
9: petscis.h - index sets petscviewer.h - viewers
10: */
11: #include <petscmat.h>
13: int main(int argc,char **args)
14: {
15: Mat mesh,dual;
16: PetscInt Nvertices = 6; /* total number of vertices */
17: PetscInt ncells = 2; /* number cells on this process */
18: PetscInt *ii,*jj;
19: PetscMPIInt size,rank;
20: MatPartitioning part;
21: IS is;
23: PetscInitialize(&argc,&args,(char*)0,help);
24: MPI_Comm_size(MPI_COMM_WORLD,&size);
26: MPI_Comm_rank(MPI_COMM_WORLD,&rank);
28: PetscMalloc1(3,&ii);
29: PetscMalloc1(6,&jj);
30: ii[0] = 0; ii[1] = 3; ii[2] = 6;
31: if (rank == 0) {
32: jj[0] = 0; jj[1] = 1; jj[2] = 2; jj[3] = 1; jj[4] = 2; jj[5] = 3;
33: } else {
34: jj[0] = 1; jj[1] = 4; jj[2] = 5; jj[3] = 1; jj[4] = 3; jj[5] = 5;
35: }
36: MatCreateMPIAdj(MPI_COMM_WORLD,ncells,Nvertices,ii,jj,NULL,&mesh);
37: MatMeshToCellGraph(mesh,2,&dual);
38: MatView(dual,PETSC_VIEWER_STDOUT_WORLD);
40: MatPartitioningCreate(MPI_COMM_WORLD,&part);
41: MatPartitioningSetAdjacency(part,dual);
42: MatPartitioningSetFromOptions(part);
43: MatPartitioningApply(part,&is);
44: ISView(is,PETSC_VIEWER_STDOUT_WORLD);
45: ISDestroy(&is);
46: MatPartitioningDestroy(&part);
48: MatDestroy(&mesh);
49: MatDestroy(&dual);
50: PetscFinalize();
51: return 0;
52: }
54: /*TEST
56: build:
57: requires: parmetis
59: test:
60: nsize: 2
61: requires: parmetis
63: TEST*/