Actual source code: ex80.c
1: /*$Id: ex80.c,v 1.10 2001/04/10 19:35:44 bsmith Exp $*/
3: static char help[] = "Partition tiny grid.\n\n";
5: /*T
6: Concepts: partitioning
7: Processors: 4
8: T*/
10: /*
11: Include "petscmat.h" so that we can use matrices. Note that this file
12: automatically includes:
13: petsc.h - base PETSc routines petscvec.h - vectors
14: petscsys.h - system routines petscmat.h - matrices
15: petscis.h - index sets
16: petscviewer.h - viewers
17: */
18: #include petscsles.h
22: int main(int argc,char **args)
23: {
24: Mat A;
25: int ierr,rank,*ia,*ja,size;
26: MatPartitioning part;
27: IS is,isn;
29: PetscInitialize(&argc,&args,(char *)0,help);
30: MPI_Comm_size(PETSC_COMM_WORLD,&size);
31: if (size != 4) SETERRQ(1,"Must run with 4 processors");
32: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
34: PetscMalloc(5*sizeof(int),&ia);
35: PetscMalloc(16*sizeof(int),&ja);
36: if (rank == 0) {
37: ja[0] = 1; ja[1] = 4; ja[2] = 0; ja[3] = 2; ja[4] = 5; ja[5] = 1; ja[6] = 3; ja[7] = 6;
38: ja[8] = 2; ja[9] = 7;
39: ia[0] = 0; ia[1] = 2; ia[2] = 5; ia[3] = 8; ia[4] = 10;
40: } else if (rank == 1) {
41: ja[0] = 0; ja[1] = 5; ja[2] = 8; ja[3] = 1; ja[4] = 4; ja[5] = 6; ja[6] = 9; ja[7] = 2;
42: ja[8] = 5; ja[9] = 7; ja[10] = 10; ja[11] = 3; ja[12] = 6; ja[13] = 11;
43: ia[0] = 0; ia[1] = 3; ia[2] = 7; ia[3] = 11; ia[4] = 14;
44: } else if (rank == 2) {
45: ja[0] = 4; ja[1] = 9; ja[2] = 12; ja[3] = 5; ja[4] = 8; ja[5] = 10; ja[6] = 13; ja[7] = 6;
46: ja[8] = 9; ja[9] = 11; ja[10] = 14; ja[11] = 7; ja[12] = 10; ja[13] = 15;
47: ia[0] = 0; ia[1] = 3; ia[2] = 7; ia[3] = 11; ia[4] = 14;
48: } else {
49: ja[0] = 8; ja[1] = 13; ja[2] = 9; ja[3] = 12; ja[4] = 14; ja[5] = 10; ja[6] = 13; ja[7] = 15;
50: ja[8] = 11; ja[9] = 14;
51: ia[0] = 0; ia[1] = 2; ia[2] = 5; ia[3] = 8; ia[4] = 10;
52: }
54: MatCreateMPIAdj(PETSC_COMM_WORLD,4,16,ia,ja,PETSC_NULL,&A);
55: MatView(A,PETSC_VIEWER_STDOUT_WORLD);
57: /*
58: Partition the graph of the matrix
59: */
60: MatPartitioningCreate(PETSC_COMM_WORLD,&part);
61: MatPartitioningSetAdjacency(part,A);
62: MatPartitioningSetFromOptions(part);
63: /* get new processor owner number of each vertex */
64: MatPartitioningApply(part,&is);
65: /* get new global number of each old global number */
66: ISPartitioningToNumbering(is,&isn);
67: ISView(isn,PETSC_VIEWER_STDOUT_WORLD);
68: ISDestroy(is);
70: ISDestroy(isn);
71: MatPartitioningDestroy(part);
73: /*
74: Free work space. All PETSc objects should be destroyed when they
75: are no longer needed.
76: */
77: MatDestroy(A);
80: PetscFinalize();
81: return 0;
82: }