Actual source code: ex22.c

  1: /*$Id: ex22.c,v 1.17 2001/08/07 03:03:07 balay Exp $*/

  3: static char help[] = "Tests matrix ordering routines.\n\n";

 5:  #include petscmat.h

  9: int main(int argc,char **args)
 10: {
 11:   Mat         C;
 12:   int         i,j,m = 5,n = 5,I,J,ierr;
 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;  I = j + n*i;
 24:       if (i>0)   {J = I - n; MatSetValues(C,1,&I,1,&J,&v,INSERT_VALUES);}
 25:       if (i<m-1) {J = I + n; MatSetValues(C,1,&I,1,&J,&v,INSERT_VALUES);}
 26:       if (j>0)   {J = I - 1; MatSetValues(C,1,&I,1,&J,&v,INSERT_VALUES);}
 27:       if (j<n-1) {J = I + 1; MatSetValues(C,1,&I,1,&J,&v,INSERT_VALUES);}
 28:       v = 4.0; MatSetValues(C,1,&I,1,&I,&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: }