Actual source code: ex13.c

petsc-3.10.5 2019-03-28
Report Typos and Errors

  2: static char help[] = "Tests copying and ordering uniprocessor row-based sparse matrices.\n\n";

  4:  #include <petscmat.h>

  6: int main(int argc,char **args)
  7: {
  8:   Mat            C,A;
  9:   PetscInt       i,j,m = 5,n = 5,Ii,J;
 11:   PetscScalar    v;
 12:   IS             perm,iperm;

 14:   PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
 15:   MatCreateSeqAIJ(PETSC_COMM_SELF,m*n,m*n,5,NULL,&C);
 16:   /* create the matrix for the five point stencil, YET AGAIN*/
 17:   for (i=0; i<m; i++) {
 18:     for (j=0; j<n; j++) {
 19:       v = -1.0;  Ii = j + n*i;
 20:       if (i>0)   {J = Ii - n; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 21:       if (i<m-1) {J = Ii + n; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 22:       if (j>0)   {J = Ii - 1; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 23:       if (j<n-1) {J = Ii + 1; MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES);}
 24:       v = 4.0; MatSetValues(C,1,&Ii,1,&Ii,&v,INSERT_VALUES);
 25:     }
 26:   }
 27:   MatAssemblyBegin(C,MAT_FINAL_ASSEMBLY);
 28:   MatAssemblyEnd(C,MAT_FINAL_ASSEMBLY);

 30:   MatConvert(C,MATSAME,MAT_INITIAL_MATRIX,&A);

 32:   MatGetOrdering(A,MATORDERINGND,&perm,&iperm);
 33:   ISView(perm,PETSC_VIEWER_STDOUT_SELF);
 34:   ISView(iperm,PETSC_VIEWER_STDOUT_SELF);
 35:   MatView(A,PETSC_VIEWER_STDOUT_SELF);

 37:   ISDestroy(&perm);
 38:   ISDestroy(&iperm);
 39:   MatDestroy(&C);
 40:   MatDestroy(&A);
 41:   PetscFinalize();
 42:   return ierr;
 43: }


 46: /*TEST

 48:    test:
 49:       filter: grep -v "MPI processes"

 51: TEST*/