Actual source code: ex22.c

  2: static char help[] = "Tests matrix ordering routines.\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:   MatCreateSeqAIJ(PETSC_COMM_SELF,m*n,m*n,5,PETSC_NULL,&C);

 20:   /* create the matrix for the five point stencil, YET AGAIN */
 21:   for (i=0; i<m; i++) {
 22:     for (j=0; j<n; j++) {
 23:       v = -1.0;  Ii = j + n*i;
 24:       if (i>0)   {J = Ii - n; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 25:       if (i<m-1) {J = Ii + n; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 26:       if (j>0)   {J = Ii - 1; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 27:       if (j<n-1) {J = Ii + 1; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 28:       v = 4.0; MatSetValues(C,1,&Ii,1,&Ii,&v,INSERT_VALUES);
 29:     }
 30:   }
 31:   MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);
 32:   MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);

 34:   MatGetOrdering(C,MATORDERING_ND,&perm,&iperm);
 35:   ISView(perm,PETSC_VIEWER_STDOUT_SELF);
 36:   ISDestroy(perm);
 37:   ISDestroy(iperm);

 39:   MatGetOrdering(C,MATORDERING_RCM,&perm,&iperm);
 40:   ISView(perm,PETSC_VIEWER_STDOUT_SELF);
 41:   ISDestroy(perm);
 42:   ISDestroy(iperm);

 44:   MatGetOrdering(C,MATORDERING_QMD,&perm,&iperm);
 45:   ISView(perm,PETSC_VIEWER_STDOUT_SELF);
 46:   ISDestroy(perm);
 47:   ISDestroy(iperm);

 49:   MatDestroy(C);
 50:   PetscFinalize();
 51:   return 0;
 52: }