Actual source code: ex6.c
petsc-3.7.3 2016-08-01
2: static char help[] = "Tests reordering a matrix.\n\n";
4: #include <petscmat.h>
8: int main(int argc,char **args)
9: {
10: Mat C;
11: PetscInt i,j,m = 5,n = 5,Ii,J;
13: PetscScalar v;
14: IS perm,iperm;
16: PetscInitialize(&argc,&args,(char*)0,help);
18: MatCreate(PETSC_COMM_SELF,&C);
19: MatSetSizes(C,PETSC_DECIDE,PETSC_DECIDE,m*n,m*n);
20: MatSetFromOptions(C);
21: MatSetUp(C);
23: /* create the matrix for the five point stencil, YET AGAIN*/
24: for (i=0; i<m; i++) {
25: for (j=0; j<n; j++) {
26: v = -1.0; Ii = j + n*i;
27: if (i>0) {J = Ii - n; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
28: if (i<m-1) {J = Ii + n; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
29: if (j>0) {J = Ii - 1; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
30: if (j<n-1) {J = Ii + 1; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
31: v = 4.0; MatSetValues(C,1,&Ii,1,&Ii,&v,INSERT_VALUES);
32: }
33: }
34: MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);
35: MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);
37: MatGetOrdering(C,MATORDERINGND,&perm,&iperm);
38: ISView(perm,PETSC_VIEWER_STDOUT_SELF);
39: ISView(iperm,PETSC_VIEWER_STDOUT_SELF);
40: MatView(C,PETSC_VIEWER_STDOUT_SELF);
42: ISDestroy(&perm);
43: ISDestroy(&iperm);
44: MatDestroy(&C);
45: PetscFinalize();
46: return 0;
47: }