Actual source code: ex13.c

petsc-3.6.1 2015-08-06
Report Typos and Errors
  2: static char help[] = "Tests copying and ordering uniprocessor row-based sparse matrices.\n\n";

  4: #include <petscmat.h>

  8: int main(int argc,char **args)
  9: {
 10:   Mat            C,A;
 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,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:   MatConvert(C,MATSAME,MAT_INITIAL_MATRIX,&A);

 36:   MatGetOrdering(A,MATORDERINGND,&perm,&iperm);
 37:   ISView(perm,PETSC_VIEWER_STDOUT_SELF);
 38:   ISView(iperm,PETSC_VIEWER_STDOUT_SELF);
 39:   MatView(A,PETSC_VIEWER_STDOUT_SELF);

 41:   ISDestroy(&perm);
 42:   ISDestroy(&iperm);
 43:   MatDestroy(&C);
 44:   MatDestroy(&A);
 45:   PetscFinalize();
 46:   return 0;
 47: }